This project is archived and is in readonly mode.

#635 ✓resolved
Pascal Friederich

has_many :through :conditions on join tables are ignored on create

Reported by Pascal Friederich | July 16th, 2008 @ 08:10 PM | in 2.x

When creating a has_many :through association with conditions on the join table, the condition is not beeing set when adding a new entry through the association.

class Group < ActiveRecord::Base
  has_many :relations
  has_many :special_users, :through => :relations, :source => :user, :conditions => {"relations.type_str" => "special"}
end

class User < ActiveRecord::Base
  has_many :permissions
end

class Relation < ActiveRecord::Base
  belongs_to :group
  belongs_to :user
end

if you add a user through the special_users association, the type_str is set to NULL on the join table.

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