Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
with - performs eager loading of related data
joinWith - performs eager loading/lazy loading of related data while using a JOIN built from relationships to fetch the main data.
For example, there is a model:
class User extends \yii\db\ActiveRecord {
public function getPosts(){
return $this->hasMany(Post::className(), ['user_id' => 'id']);
}
}
An important difference between joinWith() and with() is that the first method "sticks together" the rows of two tables and allows you to work with the data of both the primary (primary) model and the related one. The second method will allow, after sampling, to work with data only from the main model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question