From 8b5f30002a639fd6a8b2133030d808fc7990d497 Mon Sep 17 00:00:00 2001 From: Benjamin Floering Date: Sun, 17 May 2009 23:35:47 -0700 Subject: [PATCH] Fixed limited eager loading associations with numbers in the name --- activerecord/lib/active_record/associations.rb | 2 +- activerecord/test/cases/associations/eager_test.rb | 4 ++++ activerecord/test/fixtures/people.yml | 5 ++++- activerecord/test/models/person.rb | 1 + activerecord/test/schema/schema.rb | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index c5e4df4..76726b7 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1668,7 +1668,7 @@ module ActiveRecord def tables_in_string(string) return [] if string.blank? - string.scan(/([\.a-zA-Z_]+).?\./).flatten + string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten end def tables_in_hash(hash) diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index d23f86b..65049c4 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -589,6 +589,10 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1) end + def test_limited_eager_with_numeric_in_association + assert_equal people(:david, :susan), Person.find(:all, :include => [:readers, :primary_contact, :number1_fan], :conditions => "number1_fans_people.first_name like 'M%'", :order => 'readers.id', :limit => 2, :offset => 0) + end + def test_preload_with_interpolation assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions end diff --git a/activerecord/test/fixtures/people.yml b/activerecord/test/fixtures/people.yml index 3babb1f..123673a 100644 --- a/activerecord/test/fixtures/people.yml +++ b/activerecord/test/fixtures/people.yml @@ -2,14 +2,17 @@ michael: id: 1 first_name: Michael primary_contact_id: 2 + number1_fan_id: 3 gender: M david: id: 2 first_name: David primary_contact_id: 3 + number1_fan_id: 1 gender: M susan: id: 3 first_name: Susan primary_contact_id: 2 - gender: F \ No newline at end of file + number1_fan_id: 1 + gender: F diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index ec2f684..57fa641 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -10,6 +10,7 @@ class Person < ActiveRecord::Base belongs_to :primary_contact, :class_name => 'Person' has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id' + belongs_to :number1_fan, :class_name => 'Person' named_scope :males, :conditions => { :gender => 'M' } named_scope :females, :conditions => { :gender => 'F' } diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 4ee0ffe..6e8813d 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -324,6 +324,7 @@ ActiveRecord::Schema.define do t.string :first_name, :null => false t.references :primary_contact t.string :gender, :limit => 1 + t.references :number1_fan t.integer :lock_version, :null => false, :default => 0 end -- 1.6.2.5