Another way would be to store the current user in the item temporarily by defining an attribute accessor:
class Item
include Mongoid::Document
#some attributes here...
has_and_belongs_to_many :likers
attr_accessor :current_user
def user_likes
likers.include?(current_user)
end
end
and in the grape api set the current user:
get :id do
item = Item.find(.....)
item.current_user = current_user
present item, with: FancyApp::Entities::Item
end
no changes to the grape-entity model is needed.
There is no database field current_user_id
or so. No writes to database.