Skip to content

Using cause circular dependency #46

Closed
@larryzhao

Description

@larryzhao

I have two simple models:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions