提交 a3f3fab7 编写于 作者: P Pratik Naik

Add relation.from as a temporary workaround until arel relation has .from option

上级 6f5e3a04
......@@ -1632,7 +1632,8 @@ def construct_finder_arel(options = {}, scope = scope(:find))
group(construct_group(options[:group], options[:having], scope)).
order(construct_order(options[:order], scope)).
limit(construct_limit(options[:limit], scope)).
offset(construct_offset(options[:offset], scope))
offset(construct_offset(options[:offset], scope)).
from(options[:from])
relation = relation.readonly if options[:readonly]
......
......@@ -28,6 +28,14 @@ def select(selects)
create_new_relation(@relation.project(selects))
end
# TODO : This is temporary. We need .from in Arel.
attr_writer :from
def from(from)
relation = create_new_relation
relation.from = from
relation
end
def group(groups)
create_new_relation(@relation.group(groups))
end
......@@ -94,7 +102,7 @@ def to_a
:conditions => where_clause,
:limit => @relation.taken,
:offset => @relation.skipped,
:from => @relation.send(:table_sql, Arel::Sql::TableReference.new(@relation))
:from => @from
},
ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, @eager_load_associations, nil))
end
......@@ -242,8 +250,10 @@ def find_some(ids)
end
end
def create_new_relation(relation, readonly = @readonly, preload = @associations_to_preload, eager_load = @eager_load_associations)
Relation.new(@klass, relation, readonly, preload, eager_load)
def create_new_relation(relation = @relation, readonly = @readonly, preload = @associations_to_preload, eager_load = @eager_load_associations)
r = self.class.new(@klass, relation, readonly, preload, eager_load)
r.from = @from
r
end
def where_clause(join_string = "\n\tAND ")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册