function __construct(IdentifiableOrmEntity $parent, IQueryable $children, $readOnly = true) { Assert::isBoolean($readOnly); Assert::isTrue(!!$parent->getId(), 'cannot track children of unsaved parent'); $this->parent = $parent; $this->children = $children; $this->readOnly = $readOnly; $this->query = new EntityQuery($this->children); }
private function insert(IdentifiableOrmEntity $entity) { $id = $entity->_getId(); $idType = $this->identifier->getType(); $generator = !$id && $idType instanceof IOrmEntityIdGenerator ? $idType->getIdGenerator($entity) : null; $generatorType = $generator ? $generator->getType() : null; if ($generatorType && $generatorType->isPre()) { $id = $generator->generate($entity); if ($id) { $entity->_setId($id); } } $affected = $this->executeQuery(InsertQuery::create($this->physicalSchema->getTable())->setValues($this->map->disassemble($entity))); if ($generatorType && $generatorType->isPost()) { $id = $generator->generate($entity); if ($id) { $entity->_setId($id); } } $this->identityMap->add($entity); $entity->setFetched(); }