Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#635

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.

Reported by Pascal Friederich · July 16th, 2008 @ 08:10 PM

State: resolved
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Pascal Friederich
    Pascal Friederich
    • Tag changed from activerecord, bug to activerecord, bug, patch

    i made a patch on has_many_through_association.rb which adds the condition to the join table if a new object is added through the hmt association.

    it only does if the value is a string.

    The tests did all pass here but iam not a very experienced ruby programmer so please could you check this? maybe i'm totally wrong but at least i tried :)

    July 17th, 2008 @ 02:50 AM

  2. Pascal Friederich
    Pascal Friederich

    wrong email in patch.. its paukul@gmail.com (if it matters)

    here's the right one

    July 17th, 2008 @ 02:52 AM

  3. Pascal Friederich
  4. Pratik
    Pratik
    • State changed from new to incomplete
    • Assigned user set to Pratik

    Patch is missing tests.

    Thanks.

    July 20th, 2008 @ 06:35 PM

  5. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord, bug, patch to activerecord, bug, bugmash, patch

    August 3rd, 2009 @ 03:00 PM

  6. Pascal Friederich
    Pascal Friederich

    that feature was already added by mattbauer with commit 83c1934003740ed01c618a8943457a0df53e2adb

    August 3rd, 2009 @ 10:56 PM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord, bug, bugmash, patch to activerecord, bug, patch
    • State changed from incomplete to resolved

    Good catch, thanks!

    August 3rd, 2009 @ 10:59 PM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag changed from activerecord, bug, patch to activerecord bug patch
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 7th, 2010 @ 04:53 PM

  9. joson
    joson

    A Replica Breitling is a timepiece of high quality and functionality and you will have all the class, prestige and luxury of a wealthy, successful individual. By choosing from our selection of luxury Replica Watches , you can improve your self-esteem and feel confident to enter new circles of business associates and friends. These Rolex Replicas will surely enhance your style and only you will know the watch you wear did not cost you $1,000's of dollars.

    April 29th, 2011 @ 09:08 AM