lib/praxis-mapper/selector_generator.rb in praxis-mapper-4.3 vs lib/praxis-mapper/selector_generator.rb in praxis-mapper-4.4
- old
+ new
@@ -54,22 +54,30 @@
associated_resource = resource.model_map[association[:model]]
case association[:type]
when :many_to_one
add_track(resource, name)
- add_select(resource, association[:key])
+ Array(association[:key]).each do |akey|
+ add_select(resource, akey)
+ end
when :one_to_many
add_track(resource, name)
- add_select(associated_resource, association[:key])
+ Array(association[:key]).each do |akey|
+ add_select(associated_resource, akey)
+ end
when :many_to_many
- head, *tail = association.fetch(:through) do
- raise "Association #{name} on #{resource.model} must specify the " +
- "':through' option. "
+ # If we haven't explicitly added the "through" option in the association
+ # then we'll assume the underlying ORM is able to fill in the gap. We will
+ # simply add the fields for the associated resource below
+ if association.key? :through
+ head, *tail = association[:through]
+ new_fields = tail.reverse.inject(fields) do |thing, step|
+ {step => thing}
+ end
+ return add_association(resource, head, new_fields)
+ else
+ add_track(resource, name)
end
- new_fields = tail.reverse.inject(fields) do |thing, step|
- {step => thing}
- end
- return add_association(resource, head, new_fields)
else
raise "no select applicable for #{association[:type].inspect}"
end
unless fields == true