I’m using Restful API in Yii2. ( yii\rest\ActiveController )
Is there the way to use eager loading with it?
I tried this way.
/localhost/users?fields=id,email&expand=profile
But a lot of queries excuted and I think this is not better for performance, isn’t it?
Like this:
SELECT * FROM `profile` WHERE `id`=20
SELECT * FROM `profile` WHERE `id`=21
SELECT * FROM `profile` WHERE `id`=22
SELECT * FROM `profile` WHERE `id`=23
SELECT * FROM `profile` WHERE `id`=24
SELECT * FROM `profile` WHERE `id`=25
:
:
:
I think yii\rest\ActiveController is mostly useful for fast prototyping where perfomance has minor importance. For production code you might have to implement custom actions with the necessary optimizations and application-specific logic.