Skip to content

Instantly share code, notes, and snippets.

@aisuii
Created November 11, 2011 05:56
Show Gist options
  • Save aisuii/1357314 to your computer and use it in GitHub Desktop.
Save aisuii/1357314 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
module Ext
module ActiveRecord
module QueryBuilderExtension
def self.included(klass)
klass.extend ClassMethods
end
module ClassMethods
def build_left_join_query(*joins)
queries, joins = joins.flatten.partition{|q| q.is_a?(String) }
query = queries.join(' ')
dependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, joins, query)
dependency.join_associations.each{|a| query << a.association_join }
return query
end
end
end
end
end
ActiveRecord::Base.send :include, Ext::ActiveRecord::QueryBuilderExtension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment