提交 ac03bc91 编写于 作者: E Emilio Tagua

Use explicit method definition instead of metaprogramming.

上级 fa8f5c26
module ActiveRecord
class Relation
delegate :delete, :to_sql, :to => :relation
CLAUSES_METHODS = ["group", "order", "on"].freeze
delegate :to_sql, :to => :relation
attr_reader :relation, :klass
def initialize(klass, table = nil)
......@@ -22,20 +21,26 @@ def first
to_a.first
end
for clause in CLAUSES_METHODS
class_eval %{
def #{clause}!(_#{clause})
@relation = @relation.#{clause}(_#{clause}) if _#{clause}
self
end
}
end
def select!(selection)
@relation = @relation.project(selection) if selection
self
end
def on!(on)
@relation = @relation.on(on) if on
self
end
def order!(order)
@relation = @relation.order(order) if order
self
end
def group!(group)
@relation = @relation.group(group) if group
self
end
def limit!(limit)
@relation = @relation.take(limit) if limit
self
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册