public function linkRelatedModel() { if (!DI::getCellParser()->isLoadedPk($this->cell)) { return; } $loadedPk = DI::getCellParser()->getLoadedPk($this->cell); foreach (array_reverse(DI::getImporter()->models) as $model) { $isRelatedByPk = $loadedPk && $model->savedPk == $loadedPk; $attributeModelClass = $this->_standardAttribute->standardModel->className; $modelClass = $model->standardModel->className; $isRelatedByLastPk = $loadedPk === '' && $attributeModelClass != $modelClass; if ($isRelatedByPk || $isRelatedByLastPk) { $this->_relatedModel = $model; break; } } if (!$this->_relatedModel) { throw new CellException($this->cell, 'Related model not found.'); } }
public function validate() { if (!$this->_instance->validate()) { DI::getImporter()->wrongModel = $this->_instance; throw new RowException($this->row, 'Model data is not valid.'); } }