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.

:through Associations don't respect default_scope

#2297

Consider the following case:


class Taggable < ActiveRecord::Base
  has_many :taggings
  has_many :tags, :through => :taggings
end

class Tagging < ActiveRecord::Base
  belongs_to :taggable
  belongs_to :tag

  default_scope :conditions => { :enabled => true }
end

class Tag < ActiveRecord::Base
  belongs_to :tagging
end

Tag.first.tags will entirely ignore the default_scope on Tagging.

I've included a patch which depends on other patch over at http://rails.lighthouseapp.com/p...

Reported by Peter Wagenet · March 19th, 2009 @ 02:11 PM

State: resolved
Milestone: 3.x
Assigned to: Aaron Patterson Aaron Patterson
Importance: none

Activity

  1. Peter Wagenet
    Peter Wagenet

    Whoops, that should read:

    Taggable.first.tags

    March 19th, 2009 @ 02:12 PM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. Jon Leighton
    Jon Leighton
    • Assigned user set to Aaron Patterson
    • Importance changed from to

    I can confirm this is an issue. I've attached an up-to-date patch which fixes it with test cases.

    December 12th, 2010 @ 05:06 PM

  4. Aaron Patterson
    Aaron Patterson
    • State changed from new to resolved

    Fixed in master. Thanks Jon!

    December 15th, 2010 @ 07:19 PM