Method: Og::SqlStore#join

Defined in:
lib/og/store/sql/join.rb

#join(obj1, obj2, table, options = nil) ⇒ Object

Relate two objects through an intermediate join table. Typically used in joins_many and many_to_many relations.



134
135
136
137
138
139
140
141
142
# File 'lib/og/store/sql/join.rb', line 134

def join(obj1, obj2, table, options = nil)
  first, second = join_object_ordering(obj1, obj2)
  first_key, second_key = ordered_join_table_keys(obj1.class, obj2.class)
  if options
    exec "INSERT INTO #{table} (#{first_key},#{second_key}, #{options.keys.join(',')}) VALUES (#{first.pk},#{second.pk}, #{options.values.map { |v| quote(v) }.join(',')})"
  else
    exec "INSERT INTO #{table} (#{first_key},#{second_key}) VALUES (#{first.pk}, #{second.pk})"
  end
end