function save() { Assert::isFalse($this->isReadonly(), 'cannot save readonly collections'); $getter = $this->referentialProperty->getGetter(); $setter = $this->referentialProperty->getSetter(); if ($this->referentialProperty->getMultiplicity()->isNullable()) { foreach ($this->getLostTracked() as $object) { $object->{$setter}(null); $object->save(); } } else { if (sizeof($this->getLostTracked())) { $query = new EntityQuery($this->getChildren()); $this->fillQuery($query); $query->andWhere(Expression::in($this->getChildren()->getLogicalSchema()->getIdentifier(), $this->getLostTracked())); $query->delete(); } } foreach ($this->getList() as $object) { // avoid useless mutation if ($object->{$getter}() !== $this->getParentObject()) { $object->{$setter}($this->getParentObject()); } $object->save(); } }
/** * Create a php code which implements a field within the entity class * @param IMappable $entity * @param OrmProperty $property */ function toField(IMappable $entity, OrmProperty $property) { $typeImpl = ($typeImpl = $this->getImplClass()) ? $typeImpl : 'scalar'; if ($property->getMultiplicity()->isNullable()) { $typeImpl .= '|null'; } return <<<EOT \t/** \t * @var {$typeImpl} \t */ \tprotected \${$property->getName()}; EOT; }
function toGetter(IMappable $entity, OrmProperty $property) { $returnValue = ($implClass = $this->getImplClass()) ? $implClass : 'mixed'; if ($property->getMultiplicity()->isNullable()) { $returnValue .= '|null'; } $propertyName = $property->getName(); $capitalizedPropertyName = ucfirst($propertyName); return <<<EOT \t/** \t * @return {$returnValue} \t */ \tfunction get{$capitalizedPropertyName}() \t{ //\t\tif (\$this->{$propertyName}) { // thats is what called lazy fetching //\t\t\t\$this->{$propertyName}->fetch(); //\t\t} \t\treturn \$this->{$propertyName}; \t} EOT; }