Skip to content

Instantly share code, notes, and snippets.

@the8472
Created April 5, 2012 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the8472/2312198 to your computer and use it in GitHub Desktop.
Save the8472/2312198 to your computer and use it in GitHub Desktop.
MonkeyPatch CanCan to use OUTER JOINs (requires squeel)
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