From e223216e9ac496d4dad53c7ada1406e9e15fbb55 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 1 Apr 2008 18:27:22 +0000 Subject: 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 --- .../lib/active_record/associations/association_collection.rb | 5 +++++ .../lib/active_record/associations/has_many_through_association.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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! -- cgit v1.2.3