Skip to content

Instantly share code, notes, and snippets.

View cch1's full-sized avatar

Chris Hapgood cch1

  • Sun Tribe Trading
  • Center of the Universe
View GitHub Profile
@cch1
cch1 / scoped_associations.rb
Created March 31, 2009 22:24
Monkey patch for scoped associations
module ActiveRecord
class Reflection::AssociationReflection
# Return a named scope instead of the bare ActiveRecord::Base subclass.
def klass_with_scope
k = klass_without_scope
options[:scope].nil? ? k : k.send(options[:scope])
end
alias_method_chain :klass, :scope
end
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 7f78191..e55b639 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1557,7 +1557,8 @@ module ActiveRecord
:finder_sql, :counter_sql,
:before_add, :after_add, :before_remove, :after_remove,
:extend, :readonly,
- :validate
+ :validate,
class Tag
has_many :taggings
end
class Tagging
belongs_to :tag
belongs_to :posts
# uses a string 'flag' column but could be changed to a boolean important
# column later, hence the need to encapsulate!