1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
|
# File 'lib/brick.rb', line 1695
def build(associations, base_klass, root = nil, path = '')
root ||= associations
associations.map do |name, right|
link_path = path.blank? ? name.to_s : path + ".#{name}"
ja = if name.is_a? ::Polyamorous::Join
reflection = find_reflection base_klass, name.name
reflection.check_validity!
reflection.check_eager_loadable!
klass = if reflection.polymorphic?
name.klass || base_klass
else
reflection.klass
end
::ActiveRecord::Associations::JoinDependency::JoinAssociation.new(
reflection, build(right, klass, root, link_path), name.klass, name.type
)
else
reflection = find_reflection base_klass, name
reflection.check_validity!
reflection.check_eager_loadable!
if reflection.polymorphic?
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
end
::ActiveRecord::Associations::JoinDependency::JoinAssociation.new(
reflection, build(right, reflection.klass, root, link_path)
)
end
ja.instance_variable_set(:@link_path, link_path) ja.instance_variable_set(:@assocs, root)
ja
end
end
|