3

Let's say I have:

class Post
  has_many :tags, :through => :taggings
  has_many :taggings
end

Notice there's no :include. Now say I want to retrieve all taggings and tags in the same query. How could I do that?

I'm looking for something like:

taggings = post.taggings(:include => tags) # doesn't work

I could make a custom query or add a third association to Post with an :include, but neither feels right.

mahemoff
  • 44,526
  • 36
  • 160
  • 222

1 Answers1

1

I think you can use includes on the association proxy as you would with the model class:

taggings = post.taggings.includes(:tag)
rabusmar
  • 4,084
  • 1
  • 25
  • 29