mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed limited eager loading associations with numbers in the name [#2668 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
49afe81a13
commit
27de7f150b
5 changed files with 11 additions and 2 deletions
|
@ -1668,7 +1668,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def tables_in_string(string)
|
def tables_in_string(string)
|
||||||
return [] if string.blank?
|
return [] if string.blank?
|
||||||
string.scan(/([\.a-zA-Z_]+).?\./).flatten
|
string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
def tables_in_hash(hash)
|
def tables_in_hash(hash)
|
||||||
|
|
|
@ -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)
|
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
|
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
|
def test_preload_with_interpolation
|
||||||
assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions
|
assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions
|
||||||
end
|
end
|
||||||
|
|
3
activerecord/test/fixtures/people.yml
vendored
3
activerecord/test/fixtures/people.yml
vendored
|
@ -2,14 +2,17 @@ michael:
|
||||||
id: 1
|
id: 1
|
||||||
first_name: Michael
|
first_name: Michael
|
||||||
primary_contact_id: 2
|
primary_contact_id: 2
|
||||||
|
number1_fan_id: 3
|
||||||
gender: M
|
gender: M
|
||||||
david:
|
david:
|
||||||
id: 2
|
id: 2
|
||||||
first_name: David
|
first_name: David
|
||||||
primary_contact_id: 3
|
primary_contact_id: 3
|
||||||
|
number1_fan_id: 1
|
||||||
gender: M
|
gender: M
|
||||||
susan:
|
susan:
|
||||||
id: 3
|
id: 3
|
||||||
first_name: Susan
|
first_name: Susan
|
||||||
primary_contact_id: 2
|
primary_contact_id: 2
|
||||||
|
number1_fan_id: 1
|
||||||
gender: F
|
gender: F
|
|
@ -10,6 +10,7 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :primary_contact, :class_name => 'Person'
|
belongs_to :primary_contact, :class_name => 'Person'
|
||||||
has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id'
|
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 :males, :conditions => { :gender => 'M' }
|
||||||
named_scope :females, :conditions => { :gender => 'F' }
|
named_scope :females, :conditions => { :gender => 'F' }
|
||||||
|
|
|
@ -324,6 +324,7 @@ ActiveRecord::Schema.define do
|
||||||
t.string :first_name, :null => false
|
t.string :first_name, :null => false
|
||||||
t.references :primary_contact
|
t.references :primary_contact
|
||||||
t.string :gender, :limit => 1
|
t.string :gender, :limit => 1
|
||||||
|
t.references :number1_fan
|
||||||
t.integer :lock_version, :null => false, :default => 0
|
t.integer :lock_version, :null => false, :default => 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue