Nested bean export creation

28 views
Skip to first unread message

Francesco Petronella

unread,
May 23, 2023, 9:06:43 AM5/23/23
to redbeanphp
Good morning everyone. I have a structure like this

"gamematch" contains a xownList of "matchteam"s
"matchteam"  refers to a "registration" via registration_id
"registration" as "name" as property

what would be the correct way to obtain a structure like this
[
1 => {//gamematch
          id => 1,
          xownMatchteamList=> [
                  {
                            id => 1,
                            registration => { id => 1, name => "Jonh"}
                  },
                  {
                            id => 1,
                            registration => { id => 2, name => "Beth"}
                  }
         ]
},
.....
]

with a single SELECT done using getAll?
The getAll() 'm using is the following:

R::getAll("SELECT gamematch.*,matchteam.* FROM gamematch, matchteam, registration WHERE gamematch.id = matchteam.gamematch_id AND matchteam.registration_id = registration.id")

I've tried using exportAll() but it only goes one layer deep into parent bean conversion, and so i'm not able to convert the registration_ids to registration

Any suggestion would be more then welcome. Thanks in advance

Benoit Pruneau

unread,
May 31, 2023, 11:32:22 AM5/31/23
to redbeanphp
I think, in your case, there is no way to have this structure of Beans using only one SQL query.
But you can have an array structure; less obvious, but faster.

If you must use Beans, I suggest using loadJoined() to reduce the number of queries.
Reply all
Reply to author
Forward
0 new messages