1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
|
# File 'lib/brick.rb', line 1997
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
|