ryanb/cancan — Issue #560: ActiveRecordAdapter::merge_joins can throw away joins
Author: DavidMikeSimon
Created: 2012-02-15 22:48:28+00:00
State: open

When merging association hashes from rules to create an SQL join pattern, the merge_joins method will overwrite an earlier subhash with a later empty one.

For example:

h = {:foo => {:bar => {}}}
merge_joins(h, {:foo => {}})
h # => {:foo => {}}

For now I've corrected this in my own app with a monkey patched version of the method:

def merge_joins(base, add)
add.each do |name, nested|
if base[name].is_a?(Hash)
merge_joins(base[name], nested) unless nested.empty?
else
base[name] = nested
end
end
end