-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Sideloading associations #1088
Sideloading associations #1088
Conversation
3e08b08
to
d0477a1
Compare
d0477a1
to
5eb5c2e
Compare
👍 This is working for me so far in my application! I had to tweak one thing though. I have a has_one and this sideloads it as a singleton object as apposed to an array. Before I'm pretty sure it still stuck it in an array. Had to do the following hack... has_many :foos
def foos
[ object.foo ]
end VS has_one :foo |
@criten could you elaborate? I haven't used a has_one in my app yet, so I'm uncertain what the exact issue you found is / was |
Just edited my comment. |
interesting. Does has_one work in normal AMS, nested the data under |
Yeah.. just checked. To be a bit more clear.... # 0.9.X
class FooSerializer < ActiveModel::Serializer
has_one :bar
end bar: {
foo_id: 1
},
foos:
[{
id: 1
}] VS # 0.10.X
class FooSerializer < ActiveModel::Serializer
has_one :foo
end bar: {
foo_id: 1
},
foo:
{
id: 1
} |
I think that's what its doing.... |
kk, I'll see if I can come up with a test and fix it |
Implementation idea for sideloading to help out JS Frameworks added tests for sideloading and binding.pry for debugging added configuration option for sideloading associations switching computers tests pass revert require of dev-friendly gems - as they aren't as compatible as AMS is aiming to be also fixed a bug introduced by the sideloading - no existing tests caught the bug before initial push added a test for has_one
5eb5c2e
to
0d1a1a2
Compare
@criten I added a test but was not able to replicate. :-( Is there anyway you have time to monkey around with the sideload_test.rb tests and see if you can replicate in there? (I did add two more tests, though, for has_one and belongs_to) |
Heh, About a week ago I've started to make my own implementation of the same thing. Currently it is documented but doesn't contain the proper specs, that is why I haven't yet made a PR. In general It works for me, but doesn't support custom names of associations and excludes not sideloaded reflections from a "relationships" object. Also, I've added a sideloading to the SerializedResource's initialization process and now doubt about this decision. |
👍 |
I don't think this is working for me with nested has_many? Do you know if that works? |
Does regular AMS work with nested has many? When I was looking through the I do know that tested has many doesn't work. But I also don't know if it's On Fri, Aug 28, 2015, 5:00 PM Zachary Mattor [email protected]
|
It definitely worked in version 0.9... |
I'll take a look at the tests on master when I can, and see if there is a On Fri, Aug 28, 2015, 5:06 PM Zachary Mattor [email protected]
|
@criten it looks like nested has many is broken in master: NullVoxPopuli@15147de |
if sideload | ||
association_ids = {} | ||
@hash.map do |association_name, associated_models| | ||
# TODO: use active support inflectors? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say yes, but I'm concerned with ppl using AMS outside Rails context.
I'd keep it like that and come back at it after Rails 5 release
Closing, in favor of an implementation based off my refactored work (#1111) |
Hey all, since this is a highly requested feature, I figured I'd take a stab at it since I need it for my own ember work.
Thoughts on the implementation?
The goal of this is to address needs of #938 and #899
Usage
And that's it. :-)
No need to have embed: :ids on all the associations.