28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'activerecord/lib/active_record/associations/alias_tracker.rb', line 28
def self.initial_count_for(connection, name, table_joins)
quoted_name = nil
counts = table_joins.map do |join|
if join.is_a?(Arel::Nodes::StringJoin)
quoted_name ||= connection.quote_table_name(name)
join.left.scan(
/JOIN(?:\s+\w+)?\s+(?:\S+\s+)?(?:#{quoted_name}|#{name})\sON/i
).size
elsif join.is_a?(Arel::Nodes::Join)
join.left.name == name ? 1 : 0
else
raise ArgumentError, "joins list should be initialized by list of Arel::Nodes::Join"
end
end
counts.sum
end
|