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)
|
||||
return [] if string.blank?
|
||||
string.scan(/([\.a-zA-Z_]+).?\./).flatten
|
||||
string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten
|
||||
end
|
||||
|
||||
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)
|
||||
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
|
||||
|
|
5
activerecord/test/fixtures/people.yml
vendored
5
activerecord/test/fixtures/people.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue