-
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
Add docs for include
in Json adapter.
#1243
Comments
That's interesting! Do you know if fields or something relevant is also working with JSON adapter? If not is there any interest to send a pull request for that ? Cause I really need it and I am going to implement it anyway.. |
@vasilakisfil Currently you can use the |
I am not sure extending the Json adapter to fit the broader JSON API style |
given that's an adapter I don't think it's an issue. Plus there should be
|
Oh yeah, AMS is deisgned in such a way that you can create your own adapter and/or extend an existing one. I agree the migration from 0.8/0.9 should be made as easy as possible, I'm just not sure what's the best way to make that happen. |
maybe for the initial 0.10 release, we could copy the old adapters? maybe name them |
and then in the next release after 0.10, remove them? |
First we have to make sure it is actually possible to build such legacy adapters. |
@beauby, is there any reason to use the option I have a use case where a user can have many sessions, in order to be able to sign them all out in case something bad happens. I have something like this: class SessionsController
# ...
render json: @session, include: 'user'
# ...
end
class SessionSerializer
# ...
# I am not asking for the "UserSerializer" to include the "sessions" relationship.
# Nevertheless, it does. The "UserSerializer", for its own logical reasons, also
# declares its own relationship with "sessions" and other models.
# I should explicitly use the "include" option here if I wanted the other relationships
# to be included.
has_one :user, serializer: UserSerializer # include: ['other', 'relationships']
# ...
end In my use case, I don't want the relationships of the |
@phcoliveira Could you open a separate issue with the definition of your serializers and your render calls and a description of the unexpected behavior? |
The include option does not seem to work for me w/the JSON adapter in RC3 at least. I cannot get it to include associations 2 levels down; just the top level seems to get included. Take the following for example:
The |
@bdmac Did you specify the |
Yes I tried that and also the more specific flavored of include. — On Mon, Oct 19, 2015 at 9:25 AM, Lucas Hosseini notifications@github.com
|
@bdmac Could you open a separate issue in which you provide your models, serializers and |
@beauby This is a great issue. As the domain master of includes, I'd love if you added some docs of how it behaves and what data structures are inputs and outputs. |
I'm seeing what might be the same issue. I can't really get any use out of the I have an Organization: class OrganizationSerializer < ActiveModel::Serializer
attributes :id, :name, :created_at
has_many :apps, class_name: 'Client::Application', serializer: ClientAppSerializer
has_many :services
end and a ClientAppSerializer: class ClientAppSerializer < ActiveModel::Serializer
attributes :id, :name, :created_at
belongs_to :organization
end and a ServiceSerializer: class ServiceSerializer < ActiveModel::Serializer
attributes :id, :name, :created_at, :updated_at
belongs_to :organization
end Pretty simple, right? Let's say I want to serialize starting at the App level: render json: @app, serializer: ClientAppSerializer I'll get the serialized data for the App, and the serialized data for the Organization, but the Organization won't have any Services array. So I try this... render json: @app, serializer: ClientAppSerializer, include: 'organization.services' ... but nothing changes in my serialized output. No services. Am I missing something fundamental here? |
@mepatterson Could you open a separate issue adding the current output you're getting? |
Done. #1421 |
Hello, guys. Can you tell me, please, whether it's possible to use this option inside the serializer class itself class FooSerializer < ActiveModel::Serializer
attributes :foo, :bar, :baz
# something like this
include: '*'
end rather than inside controller? |
@d3crypt3d short answer is no. It's an adapter option. Please open a new issue to make a proposal if you'd like to discuss further, or better, join us on the slack chat. See https://github.com/rails-api/active_model_serializers/blob/master/CONTRIBUTING.md |
@bf4 sorry for bothering, but is it issue relevant either? Quick check showed that |
@charlie-wasp I had thought it did... we have tests... but it's been a while since I worked on that area... |
@charlie-wasp Would love a PR to improve :) |
The
include
option with Json adapter works the same as with the JsonApi adapter, but it's not written anywhere in the docs.The text was updated successfully, but these errors were encountered: