Skip to content

DataCollection ignores included parameters #460

Closed Answered by andumy
andumy asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, so after a lot of digging through the package code, it seems that the proper solution is the following:

return new JsonResponse(
    (new Foo(
         Bar::collection(BarModel::all())
    ))->include('bars.description')
);

Explanation

It seems that when a Data is transformed (toArray, toJson, jsonSerialized, etc), the DataCollection properties are "flattened". This means that instead of treating the partial tree of each individual DataCollection (Bar) from the transformed Data (Foo), only the partial tree of the big Data (Foo) will be treated. The contained DataCollection of the Data will be flattened as sub-properties.

In my example, because I was including properties into Bar, I wa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rubenvanassche
Comment options

Answer selected by andumy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants