Difference between #8 and #9 of
Relational Query - Lazy Loading and Eager Loading in Yii 2.0

Revision #9 has been created by softark on Apr 1, 2016, 1:05:43 PM with the memo:

Added mention to NOSQL relation
« previous (#8) next (#10) »

Changes

Title unchanged

Relational Query - Lazy Loadnig and Eager Loading in Yii 2.0

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

relational query, lazy loading, eager loading, with, join, joinWith

Content changed

It's well known that there are **Lazy Loading** approach and **Eager Loading** approach in the relational query. But it's very important to know how the Eager Loading approach works in Yii 2, since i. It has changed drastically from that of Yii 1.1, and there are common misunderstandings about it in the community.

In the following sections, we assume an example of 1:N relation like this:
[...]
"It's more effective, isn't it?"

Yes, it looks more effective, and actually
it is sometimes. In fact, Yii 1.1 did havehad this single query approach using JOIN, along with the multiple query approach without JOIN.

But the single query approach has a fatal drawback when you want to use **LIMIT** and/or **OFFSET**.
[...]
Although it will fetch 10 rows, it doesn't mean 10 authors since every author can have multiple posts.

So, considering this, that and the other,Among other major reasons that the developers have considered is that a relation between relational db and NOSQL db can be easily implemented with the separated query approach. And **Yii 2 has discarded the single query approach for the Eager Loading**. Please remember, in Yii 2, **the related models are always fetched with a separated query**.

What join and joinWith Do?
--------------------------

Along with **'with'**, we also have **'join'**, **'joinWith'** and the likes which we can use to construct the query. They are useful when you want to filter the result by an attribute of the related model.
[...]
10 0
6 followers
Viewed: 58 562 times
Version: 2.0
Category: Tutorials
Written by: softark
Last updated by: samdark
Created on: Jan 9, 2016
Last updated: 5 years ago
Update Article

Revisions

View all history