Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure consistent sort order in
ActiveModel#serializable_hash
when …
…using `only` option This is a bit of a nitpick, but say you do this: ```ruby user.as_json(only: [:email, :name]).keys ``` The result will depend on the order that the columns were added to your database (or in a test environment, the order of the columns in your `structure.sql`). ie. you might get `["email", "name"]` or `["name", "email"]`. In the specific case that you've provided `only` you are being explicit about which fields should be returned, so we can also be explicit about the order that they are returned in. This PR implements that. Now it will always return fields based on the order they're provided to the `only` argument, so in this case it would always be `["email", "name"]`.
- Loading branch information