Loads the entity or entity collection for this relation

@param EntityInterface $entity

@return EntityCollectionInterface|EntityInterface[]
554614
public function load(EntityInterface $entity)
    {
        $repository = $this->getParentRepository();

        $query = $repository->find()
            ->where($this->getConditions($entity))
            ->limit($this->limit);
        $this->addJoinTable($query);
        $this->checkConditions($query)
            ->checkOrder($query);

        /** @var EntityCollectionInterface $collection */
        $collection = $query->all();

        $collection
            ->setParentEntity($entity)
            ->getEmitter()
            ->addListener(EntityAdded::ACTION_ADD, [$this, 'add'])
            ->addListener(EntityRemoved::ACTION_REMOVE, [$this, 'remove']);

        return $collection;
    }
940206
private function readClassProperties($entity)
    {
        $className = get_class($entity);
        if (isset($this->entityProperties[$className])) {
            return $this->entityProperties[$className];
        }

        $reflectionClass = new \ReflectionClass($entity);
        $inheritedProperties = array_merge($this->getParentProperties($reflectionClass), $reflectionClass->getProperties());

        $properties = [];
        foreach ($inheritedProperties as $property) {
            $properties[$property->getName()] = $property;
        }

        $this->entityProperties[$className] = $properties;

        return $properties;
    }
331804
protected function getEntityDataArray(EntityInterface $entity)
    {
        $metadata = $this->getEntityMetadata();
        $array = [];
        
        foreach ($this->getHydrator()->extract($entity) as $sqlName => $value) {
            if ($sqlName !== $metadata->getIdentifier() && null !== $value) {
                $array[$metadata->getRawSQLName($metadata->getName($sqlName))] = $value;
            }
        }
        
        return $array;
    }
491575
public function fields(EntityInterface $entity)
    {
        $fields = [];
        foreach ((array)$this->getConfig('fields') as $field) {
            if (!$entity->isDirty($field)) {
                continue;
            }
            $fields[$field] = $entity->$field;
            $entity->setDirty($field, false);
        }

        return $fields;
    }
1004778
public function getRepository(Entity $entity)
    {
        $repo = $this->getRepositories()[get_class($entity)];

        return $this->$repo;
    }
148795
protected function retrieveModels(array $entity = [])
    {
        $models = [];
        foreach ((array) $entity as $node) {
            $models[] = $this->models->get($node);
        }

        if (empty($models)) {
            $models = $this->models->all();
        }

        return $models;
    }
793182
public function loadCollection(PersistentCollectionInterface $collection)
    {
        $mapping = $collection->getMapping();
        switch ($mapping->association) {
            case PropertyMetadata::ASSOCIATION_TYPE_EMBED_MANY:
                $this->loadEmbedManyCollection($collection);
                break;

            case PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_MANY:
                if ($mapping->repositoryMethod !== null) {
                    $this->loadReferenceManyWithRepositoryMethod($collection);
                } else {
                    if ($mapping->isOwningSide) {
                        $this->loadReferenceManyCollectionOwningSide($collection);
                    } else {
                        $this->loadReferenceManyCollectionInverseSide($collection);
                    }
                }
                break;
        }
    }
579597
public static function getRelationships(IEntity $entity): array
	{
		$return = [[], [], []];
		foreach ($entity->getMetadata()->getProperties() as $propertyMeta) {
			if ($propertyMeta->relationship === null) {
				continue;
			}

			$name = $propertyMeta->name;
			if (!$propertyMeta->relationship->cascade['remove']) {
				$return[2][$name] = $propertyMeta;
				continue;
			}

			$rawValue = $entity->getRawValue($name);
			if ($rawValue === null && $propertyMeta->isNullable) {
				continue;
			}

			$property = $entity->getProperty($name);
			if ($property instanceof IRelationshipContainer) {
				$value = $entity->getValue($name);
				if ($value) {
					if ($propertyMeta->relationship->type === Relationship::ONE_HAS_ONE && !$propertyMeta->relationship->isMain) {
						$return[0][$name] = $value;
					} else {
						$return[1][$name] = $value;
					}
				}

			} elseif ($property instanceof IRelationshipCollection) {
				$return[0][$name] = $entity->getValue($name);
			}
		}

		return $return;
	}
546477
public function load(Entity $entity)
    {
        /** @var \Slick\Orm\Sql\Select $sql */
        $sql = call_user_func_array(
            array($this->getRelatedEntity(), 'find'),
            []
        );
        $pmk = $this->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql->where(
            [
                "{$table}.{$this->getForeignKey()} = :id" => [
                    ':id' => $this->getEntity()->$pmk
                ]
            ]
        );
        return $sql->first();
    }
1355001
public function reverseMap(EntityInterface $entity): array
    {
        /** @var $entity Invoice */
        $services = [];

        foreach ($entity->getServices() as $service) {
            $services[] = [
                'id' => $service->getId(),
                'name' => $service->getName(),
                'tax_symbol' => $service->getTaxSymbol(),
                'unit' => $service->getUnit(),
                'quantity' => $this->reverseMapQuantity($service->getQuantity()),
                'unit_net_price' => $this->reverseMapPrice($service->getUnitNetPrice()),
                'net_price' => $this->reverseMapPrice($service->getNetPrice()),
                'gross_price' => $this->reverseMapPrice($service->getGrossPrice()),
                'tax_price' => $this->reverseMapPrice($service->getTaxPrice()),
                'symbol' => $service->getSymbol(),
                'discount' => $service->getDiscount(),
                'unit_net_price_before_discount' => $this->reverseMapPrice($service->getUnitNetPriceBeforeDiscount()),
            ];
        }

        return [
            'id' => $entity->getId(),
            'number' => $entity->getNumber(),
            'currency' => $entity->getCurrency(),
            'paid_price' => $this->reverseMapPrice($entity->getPaidPrice()),
            'notes' => $entity->getNotes(),
            'kind' => $entity->getKind(),
            'payment_method' => $entity->getPaymentMethod(),
            'recipient_signature' => $entity->getRecipientSignature(),
            'seller_signature' => $entity->getSellerSignature(),
            'invoice_date' => $this->reverseMapDate($entity->getInvoiceDate()),
            'sale_date' => $this->reverseMapDate($entity->getSaleDate()),
            'status' => $entity->getStatus(),
            'payment_date' => $this->reverseMapDate($entity->getPaymentDate()),
            'paid_date' => $this->reverseMapDate($entity->getPaidDate()),
            'net_price' => $this->reverseMapPrice($entity->getNetPrice()),
            'tax_price' => $this->reverseMapPrice($entity->getTaxPrice()),
            'gross_price' => $this->reverseMapPrice($entity->getGrossPrice()),
            'client_id' => $entity->getClientId(),
            'client_company_name' => $entity->getClientCompanyName(),
            'client_street' => $entity->getClientStreet(),
            'client_city' => $entity->getClientCity(),
            'client_post_code' => $entity->getClientPostCode(),
            'client_tax_code' => $entity->getClientTaxCode(),
            'client_country' => $entity->getClientCountry(),
            'bank_name' => $entity->getBankName(),
            'bank_account' => $entity->getBankAccount(),
            'swift' => $entity->getSwift(),
            'vat_exemption_reason' => $entity->getVatExemptionReason(),
            'sale_type' => $entity->getSaleType(),
            'invoice_date_kind' => $entity->getInvoiceDateKind(),
            'services' => $services,
        ];
    }
496208
public function fillCollectionWithRelations(CollectionInterface $collection)
    {
        if (!$collection->count()) {
            return $collection;
        }

        foreach ($this->getWith() as $relation) {
            $relation->fillCollection($collection);
        }

        return $collection;
    }
80978
public function load(EntityInterface $entity)
    {
        $adapter = $this->getAdapter();

        $relTable = $this->getParentTableName();
        $relPmk = $this->getParentPrimaryKey();

        $table = $this->getEntityDescriptor()->getTableName();
        $pmk = $this->getEntityDescriptor()->getPrimaryKey();
        $fnk = $this->getForeignKey();

        $onClause = "{$relTable}.{$relPmk} = {$table}.{$fnk}";

        $data = Sql::createSql($adapter)
            ->select($relTable)
            ->join($table, $onClause, null)
            ->where([
                "{$table}.{$pmk->getField()} = :id" => [
                    ':id' => $entity->{$pmk->getName()}
                ]
            ])
            ->first();

        $relEntity = $this->getParentEntityMapper()->createFrom($data);

        return null == $relEntity ? null :$this->registerEntity($relEntity);
    }
125538
public function attachEntityFields(EntityInterface $entity)
    {
        $_fields = [];
        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            if ($entity->has($field->get('name'))) {
                $this->_fetchPost($field);
            }

            $field->fieldAttached();
            $_fields[] = $field;
        }

        $entity->set('_fields', new FieldCollection($_fields));

        return $entity;
    }
37425
protected function load($entityId)
    {
        $table = $this->getEntityDescriptor()->getTableName();
        $primaryKey = $this->getEntityDescriptor()
            ->getPrimaryKey()
            ->getField();

        return $this->find()
            ->where([
                "{$table}.{$primaryKey} = :id" => [':id' => $entityId]
            ])
            ->first();
    }
481724
public function loadEntity($entity, $entity_id)
    {
        try {
            $handlers = $this->getHandlers();
            return Handler::call($handlers, $entity, 'data', array($entity_id));
        } catch (Exception $ex) {
            return array();
        }
    }
306712
protected function removeEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->remove($entity);
    }
558707
protected function findAndRemove(EntityInterface $entity = null)
    {
        if (null == $entity) {
            return $entity;
        }

        /** @var EntityInterface $existent */
        foreach ($this->data as $key => $existent) {
            if ($existent->getId() == $entity->getId()) {
                parent::remove($key);
                $this->getEmitter()
                    ->emit(
                        new EntityRemoved(
                            $entity,
                            ['collection' => $this]
                        )
                    );
                break;
            }
        }
        
        return $entity;
    }