This project is archived and is in readonly mode.

#2451 ✓stale
David Lee

has_many :through associations give different results depending on eager-loading via :include

Reported by David Lee | April 7th, 2009 @ 11:40 PM | in 3.x


class User
  has_many :comments
  has_many :posts, :through => :comments
end

class Comment
  belongs_to :user
  belongs_to :post
end

x = User.create
x.comments.create :post_id => nil

x.posts #=> []

x = User.find :first

x.posts #=> []

x = User.find :first, :include => [:posts]
x.posts #=> [nil] !!!

I'm not sure if posts should return [] or [nil], but the result should be consistent regardless of whether the association was eager-loaded or not.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages