1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
|
# File 'lib/brick.rb', line 1680
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
|