diff options
author | Rick Olson <technoweenie@gmail.com> | 2008-04-01 18:27:22 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2008-04-01 18:27:22 +0000 |
commit | e223216e9ac496d4dad53c7ada1406e9e15fbb55 (patch) | |
tree | c363adab1d0b7fcc7bfaea8b8c44e0f17ab61794 /activerecord/lib | |
parent | 4e07037afa7081538a4e6386464348f23d020585 (diff) | |
download | rails-e223216e9ac496d4dad53c7ada1406e9e15fbb55.tar.gz rails-e223216e9ac496d4dad53c7ada1406e9e15fbb55.tar.bz2 rails-e223216e9ac496d4dad53c7ada1406e9e15fbb55.zip |
Add efficient #include? to AssociationCollection (for has_many/has_many :through/habtm). [stopdropandrew]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9200 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index d8b988d889..3b8954e435 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -159,6 +159,11 @@ module ActiveRecord end end + def include?(record) + return false unless record.is_a?(@reflection.klass) + return @target.include?(record) if loaded? + exists?(record) + end protected def method_missing(method, *args) diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 83c9865205..7d418ba701 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -1,6 +1,6 @@ module ActiveRecord module Associations - class HasManyThroughAssociation < AssociationProxy #:nodoc: + class HasManyThroughAssociation < AssociationCollection #:nodoc: def initialize(owner, reflection) super reflection.check_validity! |