Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular references when using explicit, standalone representers #219

Open
sbwoodside opened this issue Jun 20, 2017 · 1 comment
Open

Comments

@sbwoodside
Copy link

Example:

class CompaniesRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI.resource :companies
  has_one :owner, class: User, decorator: UsersRepresenter
end

class UsersRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI.resource :users
  has_many :companies, extend: CompaniesRepresenter, class: Company
end

And then in the rails console: pp CompaniesRepresenter.new(Company.first).as_json and I get SystemStackError: stack level too deep and a stack trace with ... 9450 levels...

Is there a better way to handle this?

@sbwoodside
Copy link
Author

At the moment I'm using what I think is called an inline representer:

class CompanyRepresenter < Roar::Decorator
  include Roar::JSON
  include Roar::Hypermedia

  property :id
  property :name
  property :description

  property :owner, class: User do
    property :id
    property :name
  end

  link(:self) { "/#{represented.class}/#{represented.id}" }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant