Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationships JSON #75

Closed
wants to merge 3 commits into from
Closed

Relationships JSON #75

wants to merge 3 commits into from

Conversation

0xbad0c0d3
Copy link

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"}}

@coveralls
Copy link

coveralls commented Sep 8, 2016

Coverage Status

Coverage remained the same at 98.447% when pulling c40852e on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.447% when pulling c40852e on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.447% when pulling c40852e on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.447% when pulling c40852e on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@frioux
Copy link
Owner

frioux commented Sep 8, 2016

Please add a test demonstrating and exercising this. Thanks.

@0xbad0c0d3 0xbad0c0d3 mentioned this pull request Sep 16, 2016
@coveralls
Copy link

coveralls commented Sep 24, 2016

Coverage Status

Coverage increased (+0.003%) to 98.45% when pulling fd98a99 on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

4 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 98.45% when pulling fd98a99 on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 98.45% when pulling fd98a99 on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 98.45% when pulling fd98a99 on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 98.45% when pulling fd98a99 on 0xbad0c0d3:deepJson into 9f681d6 on frioux:master.

@frioux
Copy link
Owner

frioux commented Sep 24, 2016

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:

  1. It would break code that expected ids.
  2. It only works for relationships that happen to be exactly the same name as columns.
  3. Even if you fixed my second issue, it would be increasing the size of the returned JSON object in a way that people would have to opt out of, instead of opt in to.

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_manys, and if we fix that we can end up with loops, which I am not super interested in resolve.

What do you think?

@frioux
Copy link
Owner

frioux commented Nov 26, 2016

Closing this since it's been two months.

@frioux frioux closed this Nov 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants