Created
May 23, 2021 16:52
-
-
Save UsamaAshraf/897d3664ab8f0fc911b2939e883cd2c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostSerializer < ActiveModel::Serializer | |
attributes :id, :title, :details, :author | |
# Will run n Mongo queries for n posts being rendered. | |
def author | |
User.find(object.author_id) | |
end | |
end | |
# This is now a Mongoid document, not an ActiveRecord model. | |
class User | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment