Created
November 11, 2011 05:56
-
-
Save aisuii/1357314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- 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