FOF30\Model\DataModel\Relation::setDataFromCollection PHP Метод

setDataFromCollection() публичный Метод

Populates the internal $this->data collection from the contents of the provided collection. This is used by DataModel to push the eager loaded data into each item's relation.
public setDataFromCollection ( Collection &$data, mixed $keyMap = null ) : void
$data Collection 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
Результат 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);
                }
            }
        }
    }