-
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
A proper migration from 0.8.x guide #2082
Comments
Are you offering to help? |
No. I'm asking for help actually. I have no idea of what has been going on with 0.10.0 to offer any help. All I know that migration guide is horrible. |
Oh, I thought you were just complaining. You wouldn't believe some people make issues just to criticize. Maybe tag the person who made the guide.
… |
@bkoltai Do you think this migration guide can be rewrite so that no more custom adapter need to be introduced? |
@phuongnd08 that would be great, thanks for contributing! |
@bkoltai okay, so let me begin asking for the new way to do in 0.10.x instead of the old way in 0.8.x: In 0.8.x we return an array of hash [{}, {}] expect it to be rendered "[{}, {}]" |
Alright, I attempted to do this by introduce this class. I wonder if it should be added to AMS core class HashSerializer < ActiveModel::Serializer
def serializable_hash(adapter_options, options, adapter_instance)
object
end
end |
Another case is that in 0.8.x we get "null" when serialize nil object. In 0.10.x, what is the new way then? What should we do when an action can either return a model or a nil model (if it doesn't exist?) |
The old 0.8.x allow nested associations. Now the new 0.10.x doesn't seem to like that. What is the new way in 0.10.x supposed to be? @bf4 @bkoltai def my_association
MySerializer.new(object.my_association, scope: scope).as_json
end |
@phuongnd08 In the Rails JSON renderer ( https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_controller/metal/renderers.rb#L113-L114 ) , which AMS uses, strings are ignored. So, you can always I'm sure you recognize that using AMS to render primitives like hashes and arrays isn't a good use of a library designed to serialize objects. |
@phuongnd08 I haven't compare the different AMS versions, but if you're saying that 0.8 renders primitives, then saying that 0.10 does not might be a useful PR. Or anything that you would have liked to see here. I'm guessing the current wording was insufficient:
Closing since I think the issue is resolved, but please continue to discuss or reference this. For posterity, I"m going to link to the current ref of the guide https://github.com/rails-api/active_model_serializers/blob/80e470dcdb8b724990baf3c90d7300884c4395bf/docs/howto/upgrade_from_0_8_to_0_10.md |
I am not into keeping the 0.8.x way. We want to move forward to 0.10.x. Just need to know how. I think there is still issues to be discussed like the nested associations. Please account that many (majority?) of the user of AMS is just like me, they want to learn the way the library is supposed to work and how to hook into their project. Writing a custom adapter just to get thing backward compatible doesn't sound like a migration at all, it like hacking against your own code when you can just change it. |
I'm reading this: https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/upgrade_from_0_8_to_0_10.md
When I read through to this point: "Add ActiveModel::V08::CollectionSerializer"
I was like: "What the F is that?" I guess we should having not such non-sense migration.
We are earth people. We want to get our code align with new 0.10.x structure (so at least we will be able to do again when there is 0.20.x)
Another guide please?
The text was updated successfully, but these errors were encountered: