-
Notifications
You must be signed in to change notification settings - Fork 48
Cloning Model having fields with reference #867
Copy link
Copy link
Closed
Labels
Description
When cloning a Model, the fields are cloned as well but Field::$reference if set continues to hold Reference object owned by the original Model and not of the cloned Model.
e.g
$cloneModel = clone $originalModel;
// situation now
$cloneModel->getField('field_with_reference')->reference->getOwner() === $originalModel;
// proposed solution
$cloneModel->getField('field_with_reference')->getReference()->getOwner() === $cloneModel;
The solution would be to store only the Reference::$link under the Field::$reference (change to protected) and introduce Field::getReference() method:
public function getReference()
{
return $this->getOwner()->getRef($this->reference);
}
Reactions are currently unavailable