Answer the question
In order to leave comments, you need to log in
How can I get all related Yii2 models?
Is it possible somehow to get all related models in yii2. Or should they all be enumerated in the $model->relation way?
Answer the question
In order to leave comments, you need to log in
The relationship is "created and stored" in the model when it is first accessed, or it has been explicitly assigned via populateRelation.
Do you need to get exactly "already related models" or "all possible related models"?
If all are "already linked models" then $model->relatedRecords
, if "all possible links" then maybe you should consider naming all links like so:
public function getRelatedClient(){}
public function getRelatedUser(){}
public function getRelatedBooks(){}
$model->relatedClient;
$model->relatedUser;
$model->relatedBooks;
getRelated
. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question