Closed 0xbad0c0d3 closed 7 years ago
Please add a test demonstrating and exercising this. Thanks.
Ok, I have a bunch of problems with this. I asked for tests because the original PR was unclear as to exactly what it does. Here are my main issues, in order of importance:
I would rather add documentation on how to achieve what you've done generically than change code that people are already depending on. Another option would be to make a subclass of this called something like ToJSON::WithRelated, but even then, it is strange to include belongs_to
's but not has_many
s, and if we fix that we can end up with loops, which I am not super interested in resolve.
What do you think?
Closing this since it's been two months.
When we use relationships - your TO_JSON won't process it. For example: if table 'users' and 'plans' with relationship user.plan -> plan.id then, when we do $user->TO_JSON we'll receive this: {"user_id":1,"plan":MyAPP::Result::Plan=HASH(0x00000000)} With this patch result will be like this: {"user_id":1,"plan":{"id":1,"name":"wow"}}