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

Relation collection has "belongs_to"-Object not set #42

Closed
luxflux opened this issue Nov 1, 2012 · 0 comments
Closed

Relation collection has "belongs_to"-Object not set #42

luxflux opened this issue Nov 1, 2012 · 0 comments

Comments

@luxflux
Copy link

luxflux commented Nov 1, 2012

Hi

We have the following two models:

class Domain < PluginHelpers::HerModel
  include Her::Model
  uses_api ::PdnsPlugin.api

  has_many :records
end

class Record < PluginHelpers::HerModel
  include Her::Model
  uses_api ::PdnsPlugin.api

  belongs_to :domain

  def name_with_domain
    "name.#{domain.name}"
  end
end

Now if I do the following, there will be a request like Domain.find(1) does for every record, means a lot of overhead for informations which already have been fetched.

domain = Domain.find(1)
domain.records.each do |record|
  puts record.name_with_domain
end

I think the problem is, that record.domain has not been set even though I accessed the Record-object coming from the Domain object.
Do you have any idea how to easily add this already fetched Domain object to the Record object?

@luxflux luxflux mentioned this issue Nov 2, 2012
@remi remi closed this as completed Dec 4, 2012
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

Successfully merging a pull request may close this issue.

2 participants