-
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
undefined method `embed' #938
Comments
I'm afraid that is not currently possible with 0.10. @joaomdmoura is this a planned feature for 0.10? |
ok, thanks. |
Hey @tommyblue, indeed, @groyoh is right! Its possible to accomplish something close to it by using JSON-API, but would be a different implementation and not the '"old" JSON'. btw why not use only: has_many :pois, serializer: Api::V1::PoiSerializer This will return the serialized objects, isn't waht you need? You can map the ids if you want to, on a virtual attribute: class Api::V1::ItinerarySerializer < ActiveModel::Serializer
attributes :id, :title, : poi_ids
has_many :pois, serializer: Api::V1::PoiSerializer
def poi_ids
object.pois.map {|p| p.id}
end
end |
If I'm not wrong, your solution puts the serialized POI objects inside their Itinerary "fathers". This means that there will be a lot of replicated POI objects inside different itineraries. This is not a problem with few objects but with a lot of objects is a lot of useless weigth into the JSON |
@tommyblue Which adapter are you using? Json or JsonApi? You might want to subclass the adapter you're using to extend it. |
@bf4 I could, but I'd like to understand from @joaomdmoura if I'm saying something wrong stating that the use of thanks! |
@tommyblue indeed I didn't realised the whole scenario. It makes sense. The good news is that I'm willing to review a PR implementing it, but the bad one is that I'm busy into some other new features, so we can't work on this right now, but we might do it in a near future!! 😄 Meanwhile @kurko do you have any thoughts about it? |
thanks @joaomdmoura |
side loading is the preferred method of retrieving data for ember. for example, if your json references "tag" objects, you don't want to include the same tag data twice, so you just make an id reference. |
👍 I also need this functionality... I'll probably have to roll back to 0.9 for now. |
I'm going to work on this a bit today, as I absolutely NEED it for communicating with ember. |
I have a pull request #1088 which I hope addresses this for most people |
as for embedding ids only, would it make sense to have |
Didn't v0.9 do it on the class level? But I do see the appeal of being able to change the behavior per association. |
Here's my workaround for now, similar to @joaomdmoura above: class PostSerializer < ActiveModel::Serializer
attributes :id, :comment_ids
def comment_ids
object.comments.pluck(:id)
end
end |
@andrewhavens about right. embed was terminology from an earlier iteration of the json api spec, iirc. Subclassing an adapter (and then sharing it!) would probably be the simplest way to have the exact same behavior |
Closing for now -- It looks like there have been a couple different strategies for achieving the functionality of embed_ids, so further action could be in the form of a pull request, or expanding on the LegacyJSON PR, or something similar. |
+1. This is a necessity for |
@aandis This macro won't be re-added as it was from an earlier iteration of JSON API see #938 (comment) The docs you link to are because that repo hasn't been updated adopted-ember-addons/active-model-adapter#66 |
+1. I need this too. |
some work on this is actually being done here: #1845 |
+1. Need this too. |
@alexloginov in the latest version of AMS, |
I'm using the 0.10.0.rc1 version because 0.9.x doesn't work, but with this definition of the serializer:
I get this error:
Embed is deprecated? How can I generate the "old" JSON including associated objects, like this:
The text was updated successfully, but these errors were encountered: