kirschbaum-development / eloquent-power-joins

The Laravel magic you know, now applied to joins.
MIT License
1.39k stars 87 forks source link

Heiracly load data #146

Closed ApXaHgheJI closed 1 year ago

ApXaHgheJI commented 1 year ago

I will start with SORRY - but I didn't get the idea may be... ( previously using relation on example Yii and Yii2 FrameWorks ) - it was really helpful to use relations as join - and the data will be filled automatically to collection of Users ( for example )

Example:

Users -> posts -> comments

Users::all()->joinRealtion('posts.comments') will create an multidimensional array that will contain all the users ( and for each user will be a cell (key) posts - that will contain his posts, and each posts[collection] will have an post[key] that will contain his own comment

So its also called Nested I guess

{ "name" : "Admin", "age" : 36, "posts" : { "post1" : { "comments" : [ {"title" :"comment1"}, {"title" :"comment2"}, {"title" :"comment3"} ] }, "post2" : {}, "post3" : {} } }

ApXaHgheJI commented 1 year ago

In my case I have 2 leftJoinsts - and I was thinking that the main entity will fill the data in case the leftJoin data exists. But looks like - he just join in and that is all :(

ApXaHgheJI commented 1 year ago

btw: he put the columns that are fillable ... mhh... any way to load entire Entity ( as nested ). ?

luisdalmolin commented 1 year ago

I don't think what you are trying to achieve should be done with joins. If you are looking to get the users with their posts and the comments for each post, you should be loading the relationship directly, probably using eager loading (https://laravel.com/docs/10.x/eloquent-relationships#eager-loading).

This package helps you use SQL joins in an easier way, but is not meant to replace existing Laravel functionality.

ApXaHgheJI commented 1 year ago

@luisdalmolin unfortunately all of this requests - are making additional selects ( or 1 select )

the good example is how Yii2 ( ActiveRecord ) doing, he can use join ( and result of this join is attached to main entity as object, more of that, it can use subQuery for sub-child.

That is something helpful, when you use select + joinWith + joinWith - and there is only 1 request, will all of the data stored. Anyway - thanks.