Replies: 1 comment
-
When returning list responses via api, the auto chaperone would not be recommended because the result will contain duplicate data. Ex: {
"data": {
{ user, post{... user},
...
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Since the new
Model::automaticallyEagerLoadRelationships()
was been released I've thinking of the chaperone/setRelation method.Wouldn't it be cool and handy if models are automatically chaperoned when needed?
Take a look at the following code:
This code loads 1 board, multiple posts for that board, and then for each post it loads that same board again (with the
automaticallyEagerLoadRelationships
the code would execute 3 queries, still one too many).It looks so logical to use the existing
$board
populate the$post
when needed (aka, avoid a call to the database and use the existing board).Now I get that you can
chaperone
the board in that first code block. But the reason to "automate" this is the same as forautomaticallyEagerLoadRelationships
, it's such an easy quick win to just activate this and it avoids so much repeated bloat in the code.I'm not sure if this is even possible so I'm just dropping this as an idea here.
Beta Was this translation helpful? Give feedback.
All reactions