Skip to content

Cloning Model having fields with reference #867

@georgehristov

Description

@georgehristov

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);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions