This project is archived and is in readonly mode.

#2090 ✓resolved
Matt Bauer

has_many :through Doesn't Use Conditions For Creating New Records

Reported by Matt Bauer | February 27th, 2009 @ 12:20 AM | in 2.x

has_many :through Doesn't Use Conditions For Creating New Records. Assuming the following ActiveRecord:


class Post < ActiveRecord::Base
  has_many :skimmers, :class_name => 'Reader', :conditions => { :skimmer => true }
  has_many :impatient_people, :through => :skimmers, :source => :person

end

When a new record is created with the following code:


my_post.impatient_people.create!(:first_name => 'bob')

Creates the proper models in the readers and people tables but the record in the readers table does not have the skimmer attribute set to true. The attached patch will interrogate the conditions options and if it's a hash, add it to the attribute hash when creating the join model.

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

Referenced by

Pages