public setDataFromCollection ( |
||
$data | The relation data to push into this relation | |
$keyMap | mixed | Used by many-to-many relations to pass around the local to foreign key map |
return | void |
public function setDataFromCollection(Collection &$data, $keyMap = null)
{
$this->data = new Collection();
if (!empty($data)) {
$localKeyValue = $this->parentModel->getFieldValue($this->localKey);
/** @var DataModel $item */
foreach ($data as $key => $item) {
if ($item->getFieldValue($this->foreignKey) == $localKeyValue) {
$this->data->add($item);
}
}
}
}