public function unite(Identifiable $object, Identifiable $old) { Assert::isNotNull($object->getId()); Assert::isTypelessEqual($object->getId(), $old->getId(), 'cannot merge different objects'); $query = OSQL::update($this->getTable()); foreach ($this->getProtoClass()->getPropertyList() as $property) { $getter = $property->getGetter(); if ($property->getClassName() === null) { $changed = $old->{$getter}() !== $object->{$getter}(); } else { /** * way to skip pointless update and hack for recursive * comparsion. **/ $changed = $old->{$getter}() !== $object->{$getter}() || $old->{$getter}() != $object->{$getter}(); } if ($changed) { $property->fillQuery($query, $object); } } if (!$query->getFieldsCount()) { return $object; } $this->targetizeUpdateQuery($query, $object); return $this->doInject($query, $object); }
/** * @return InsertOrUpdateQuery **/ public function fillQuery(InsertOrUpdateQuery $query, Prototyped $object, Prototyped $old = null) { if ($old) { if ($object instanceof Identifiable) { Assert::isNotNull($object->getId()); Assert::isTypelessEqual($object->getId(), $old->getId(), 'cannot merge different objects'); } } foreach ($this->getPropertyList() as $property) { $property->fillQuery($query, $object, $old); } return $query; }