public function getChanges() : array { $md = EntityMetadataRegistry::get(get_class(parent::getEntity())); $changes = []; foreach (parent::getChanges() as $key => $value) { $column = StringUtil::underscore($key); $relation = $md->getRelation($column); // If the column isn't a relation, or the relation isn't defined by a column on the current entity, we // can skip it if ($relation === null || $md->getColumn($column) === null) { continue; } if ($value instanceof EntityInterface) { $value = $value->getId(); } $changes[$key] = $value; } return $changes; }
private static function addManyRelation(string $name, string $entity, bool $owned, array $conds = [], string $target = null) { if (!$target) { $target = StringUtil::underscore(ClassUtil::getClassName(static::class)); } EntityMetadataRegistry::get(static::class)->addRelation($name, new ManyRelation($entity, $conds, $owned, null, $target)); }