Skip to content

Commit

Permalink
Fixed limited eager loading associations with numbers in the name [#2668
Browse files Browse the repository at this point in the history
 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
floering authored and lifo committed May 18, 2009
1 parent 49afe81 commit 27de7f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -1668,7 +1668,7 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)

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)
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/associations/eager_test.rb
Expand Up @@ -589,6 +589,10 @@ def test_limited_eager_with_multiple_order_columns
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
Expand Down
5 changes: 4 additions & 1 deletion activerecord/test/fixtures/people.yml
Expand Up @@ -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
number1_fan_id: 1
gender: F
1 change: 1 addition & 0 deletions activerecord/test/models/person.rb
Expand Up @@ -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' }
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/schema/schema.rb
Expand Up @@ -324,6 +324,7 @@ def create_table(*args, &block)
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

Expand Down

0 comments on commit 27de7f1

Please sign in to comment.