Created
April 5, 2012 16:06
-
-
Save the8472/2312198 to your computer and use it in GitHub Desktop.
MonkeyPatch CanCan to use OUTER JOINs (requires squeel)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cancan/model_adapters/active_record_adapter" | |
class CanCan::ModelAdapters::ActiveRecordAdapter | |
# use squeel's symbol-predicates to convert all joins into outer joins | |
# see https://github.com/ryanb/cancan/issues/374 | |
def clean_joins(joins_hash) | |
joins = [] | |
joins_hash.each do |name, nested| | |
name = name.outer if nested.is_a? Hash | |
joins << (nested.empty? ? name : {name => clean_joins(nested)}) | |
end | |
joins | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment