1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix merge conflicts for #19938

This is a separate commit, as it is not just a changelog conflict. Want
to point out the changes in the code
This commit is contained in:
Sean Griffin 2015-10-20 16:57:47 -06:00
commit 5c32f41d52
6 changed files with 29 additions and 6 deletions

View file

@ -131,9 +131,9 @@ module ActiveRecord
def instantiate(result_set, aliases)
primary_key = aliases.column_alias(join_root, join_root.primary_key)
seen = Hash.new { |h,parent_klass|
h[parent_klass] = Hash.new { |i,parent_id|
i[parent_id] = Hash.new { |j,child_klass| j[child_klass] = {} }
seen = Hash.new { |i, object_id|
i[object_id] = Hash.new { |j, child_class|
j[child_class] = {}
}
}
@ -233,7 +233,6 @@ module ActiveRecord
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
return if ar_parent.nil?
primary_id = ar_parent.id
parent.children.each do |node|
if node.reflection.collection?
@ -253,14 +252,14 @@ module ActiveRecord
next
end
model = seen[parent.base_klass][primary_id][node.base_klass][id]
model = seen[ar_parent.object_id][node.base_klass][id]
if model
construct(model, node, row, rs, seen, model_cache, aliases)
else
model = construct_model(ar_parent, node, row, model_cache, id, aliases)
model.readonly!
seen[parent.base_klass][primary_id][node.base_klass][id] = model
seen[ar_parent.object_id][node.base_klass][id] = model
construct(model, node, row, rs, seen, model_cache, aliases)
end
end

View file

@ -24,6 +24,8 @@ require 'models/membership'
require 'models/club'
require 'models/categorization'
require 'models/sponsor'
require 'models/mentor'
require 'models/contract'
class EagerAssociationTest < ActiveRecord::TestCase
fixtures :posts, :comments, :authors, :essays, :author_addresses, :categories, :categories_posts,
@ -1218,6 +1220,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_no_queries { assert_equal 2, posts[1].categories[0].categorizations.length }
end
def test_eager_load_multiple_associations_with_references
mentor = Mentor.create!(name: "Barış Can DAYLIK")
developer = Developer.create!(name: "Mehmet Emin İNAÇ", mentor: mentor)
Contract.create!(developer: developer)
project = Project.create!(name: "VNGRS", mentor: mentor)
project.developers << developer
projects = Project.references(:mentors).includes(mentor: { developers: :contracts }, developers: :contracts)
assert_equal projects.last.mentor.developers.first.contracts, projects.last.developers.last.contracts
end
test "scoping with a circular preload" do
assert_equal Comment.find(1), Comment.preload(:post => :comments).scoping { Comment.find(1) }
end

View file

@ -15,6 +15,8 @@ class Developer < ActiveRecord::Base
end
end
belongs_to :mentor
accepts_nested_attributes_for :projects
has_and_belongs_to_many :shared_computers, class_name: "Computer"

View file

@ -0,0 +1,3 @@
class Mentor < ActiveRecord::Base
has_many :developers
end

View file

@ -1,4 +1,5 @@
class Project < ActiveRecord::Base
belongs_to :mentor
has_and_belongs_to_many :developers, -> { distinct.order 'developers.name desc, developers.id desc' }
has_and_belongs_to_many :readonly_developers, -> { readonly }, :class_name => "Developer"
has_and_belongs_to_many :non_unique_developers, -> { order 'developers.name desc, developers.id desc' }, :class_name => 'Developer'

View file

@ -253,6 +253,7 @@ ActiveRecord::Schema.define do
t.string :first_name
t.integer :salary, default: 70000
t.integer :firm_id
t.integer :mentor_id
if subsecond_precision_supported?
t.datetime :created_at, precision: 6
t.datetime :updated_at, precision: 6
@ -452,6 +453,10 @@ ActiveRecord::Schema.define do
t.string :name
end
create_table :mentors, force: true do |t|
t.string :name
end
create_table :minivans, force: true, id: false do |t|
t.string :minivan_id
t.string :name
@ -660,6 +665,7 @@ ActiveRecord::Schema.define do
t.string :name
t.string :type
t.integer :firm_id
t.integer :mentor_id
end
create_table :randomly_named_table1, force: true do |t|