lib/rom/sql/association/many_to_many.rb in rom-sql-1.0.0.beta2 vs lib/rom/sql/association/many_to_many.rb in rom-sql-1.0.0.beta3
- old
+ new
@@ -15,31 +15,35 @@
options[:through] || options[:through_relation], options[:through]
]
end
# @api public
- def call(relations)
+ def call(relations, target_rel = nil)
join_rel = join_relation(relations)
assocs = join_rel.associations
- left = assocs[target].call(relations)
+ left = target_rel ? assocs[target].(relations, target_rel) : assocs[target].(relations)
right = relations[target.relation]
left_fk = foreign_key || join_rel.foreign_key(source.relation)
schema =
if left.schema.key?(left_fk)
- left.schema.project(*(right.schema.map(&:name) + [left_fk]))
+ if target_rel
+ target_rel.schema.merge(left.schema.project(left_fk))
+ else
+ left.schema.project(*(right.schema.map(&:name) + [left_fk]))
+ end
else
right.schema.merge(join_rel.schema.project(left_fk))
end.qualified
relation = left
.inner_join(source, join_keys(relations))
.order(*right.schema.project_pk.qualified)
if view
- schema.(relation.public_send(view))
+ apply_view(schema, relation)
else
schema.(relation)
end
end