/** * {@inheritdoc} */ public function contributeToClass($fieldName, $modelObject) { parent::contributeToClass($fieldName, $modelObject); $callback = function ($kwargs) { /* @var $field RelatedField */ /** @var $related Model */ $related = $kwargs['relatedModel']; $field = $kwargs['fromField']; $field->relation->toModel = $related; $field->doRelatedClass($related, $kwargs['scopeModel']); }; Tools::lazyRelatedOperation($callback, $this->scopeModel, $this->relation->toModel, ['fromField' => $this]); }
/** * {@inheritdoc} */ public function contributeToClass($fieldName, $modelObject) { parent::contributeToClass($fieldName, $modelObject); // if through model is set if ($this->relation->through !== null) { $callback = function ($kwargs) { /* @var $field RelatedField */ /** @var $related Model */ $related = $kwargs['relatedModel']; $field = $kwargs['fromField']; $field->relation->through = $related; $field->doRelatedClass($related, $kwargs['scopeModel']); }; Tools::lazyRelatedOperation($callback, $this->scopeModel, $this->relation->through, ['fromField' => $this]); } else { $this->relation->through = $this->createManyToManyIntermediaryModel($this, $this->scopeModel); } }