1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
|
# File 'lib/brick.rb', line 1922
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
|