/** * @param \obo\Entity $owner * @param mixed $propertyValue * @param boolean $autoCreate * @return \obo\Entity|null */ public function relationshipForOwnerAndPropertyValue(\obo\Entity $owner, $propertyValue, $autoCreate = true) { $this->owner = $owner; if ($this->entityClassNameToBeConnectedInPropertyWithName === null) { $entityClassNameToBeConnected = $this->entityClassNameToBeConnected; } else { if (!($entityClassNameToBeConnected = $owner->valueForPropertyWithName($this->entityClassNameToBeConnectedInPropertyWithName))) { return null; } } $entityManagerName = $entityClassNameToBeConnected::entityInformation()->managerName; if ($propertyValue) { return $entityManagerName::entityWithPrimaryPropertyValue($propertyValue, true); } else { return ($autoCreate and $this->autoCreate and !$owner->isDeleted()) ? $entityManagerName::entityFromArray([]) : null; } }
/** * @param \obo\Entity $entity * @return string */ public function identificationKeyForEntity(\obo\Entity $entity) { return $entity->className() . $entity->valueForPropertyWithName($entity->entityInformation()->primaryPropertyName); }
/** * @param \obo\Entity $entity * @param bool $ignoreSoftDelete * @return array; */ protected static function rawDataForEntity(\obo\Entity $entity, $ignoreSoftDelete = false) { $primaryPropertyName = $entity->entityInformation()->primaryPropertyName; $specification = self::queryCarrier(); $specification->select(self::constructSelect())->where("{{$primaryPropertyName}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $entity->valueForPropertyWithName($primaryPropertyName)); if (!$ignoreSoftDelete and ($propertyNameForSoftDelete = $entity->entityInformation()->propertyNameForSoftDelete) !== "") { $specification->where("AND {{$propertyNameForSoftDelete}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, FALSE); } $data = self::rawDataForSpecification($specification); return isset($data[0]) ? $data[0] : []; }