Eager Loading In Yii 2.0 Rest

Will it be possible to use eager loading in the core implementation of REST in Yii 2.0?

e.g. is it possible to use $user = User::model()->with(‘posts’)->findAll(); (but then in Yii2 syntax)

Or this is not the idea of REST?

Did you mean

$users = User::find()->joinWith('posts')->all();

Yes, that is what I meant ;)

Is it possible to query that to a REST server with Yii2 and get the user-model with its corresponding posts-relation back?

Sure, just add relation name to fields() array.

probably I’m wrong,

You are right about that, but I needed to know what to query to the REST to get the extra field as well. Found something, which says that it is possible via the fields parameter and expand parameter (for extrafields) http://localhost/users?fields=id,email&expand=profile.

Source: http://stuff.cebe.cc/yii2docs/guide-rest.html

So I guess it is possible after all :) Yii is awesome

I striked through my message right after I realized that this can cause lazy or non-joined loading of data.

So yes, it’s possible, but requires some investigation.

Unfortunately right now I dont have time for that, will look later, unless somebody gives an answer.