You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class User < ActiveRecord::Base
has_many :notebooks, dependent: :destroy
has_many :notes, :through => :notebooks
end
class Note < ActiveRecord::Base
belongs_to :notebook
has_one :user, :through => :notebook
end
module Entities
class Note < Grape::Entity
expose :id, :title, :views_count, :slug
expose :user, :using => Entities::User
end
end
And have two simple Entity for them. And in Entities::Note, I'd like to present user model using Entities::User with the syntax :using . But I found that it only works if I require the Entities::User file before the Entities::Note file. Other wise I will get an error saying: [:error, "undefined method `represent' for #Class:0x007fde9cecc4d0"]
Is there a good way to solve this? since I am also gonna present notes inside user.
Thank you very much.
The text was updated successfully, but these errors were encountered:
@joelvh I don't think so. If there's a third Entity that want to use UserWithNotes and also need to be included in UserWithNotes, the problem is there again.
I have two simple models:
And have two simple Entity for them. And in
Entities::Note
, I'd like to present user model usingEntities::User
with the syntax :using . But I found that it only works if I require theEntities::User
file before theEntities::Note
file. Other wise I will get an error saying: [:error, "undefined method `represent' for #Class:0x007fde9cecc4d0"]Is there a good way to solve this? since I am also gonna present notes inside user.
Thank you very much.
The text was updated successfully, but these errors were encountered: