salsify/goldiloader

Not loading has_one resources

Closed this issue · 6 comments

g8d3 commented

I tried with a discussion class which:

    has_one :content, through: :assignment
    has_one :classroom, through: :assignment
    belongs_to :topic

And I got several queries for the first two. Topic is fine.

@juanpastas - Do you have a small reproducible test case for this problem?

g8d3 commented

How could I create one? doing a Rails app?

The easiest reproducible test cases to work with are gists that use the Active Record bug template (you'll have to update the gem section to include goldiloader).

In the meantime can you answer a few questions on the issue you're seeing:

  • What version of Active Record and Goldiloader are you using?
  • What is the error message + stack trace you're seeing?
  • How is the assignment association defined?
  • Does the problem still reproduce if you take Goldiloader out of your app and just use standard Rails eager loading?
g8d3 commented
  • Rails 4.2.2, latest version of goldiloader
  • I am using bullet gem to report N+1 queries, so I see the message on the page and rails server logger.
  • belongs_to :assignment, counter_cache: true
  • Problem disappears when I use current_user.discussions.includes(:classroom, :content, :topic) and delete gem from Gemfile.

@juanpastas - I couldn't reproduce this problem. I focused on the content and assignment associations and everything worked fine. The test can be found here. Can you take a look and see if you can reproduce the problem?

g8d3 commented

I tried too, but I could not reproduce it. I should have done something wrong.