4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/hayfork/join.rb', line 4
def join(relation, join_value)
case join_value
when String
relation.joins(join_value)
when Symbol
reflection = reflection_for(relation.model, join_value)
case reflection.macro
when :has_many, :has_and_belongs_to_many
relation.left_outer_joins(join_value).where(reflection.klass.arel_table[:id].not_eq(nil))
when :belongs_to, :has_one
relation.joins(join_value)
else
fail NotImplementedError, "Joins haven't been implemented for #{reflection.macro.inspect} associations"
end
else
fail NotImplementedError, "Statement#joins does not yet accept #{join_value.class} params like #{join_value.inspect}. Will this scenario work with `has_many through:` or `has_one through:`?"
end
end
|