主动记录范围的决议

时间:2017-08-23 05:15:10

标签: ruby-on-rails

是否可以添加在作用域结算时执行的代码块?例如:

@users = User.where(name: "...") #doesn't resolve yet
@users.resolved do
  puts "loaded: #{@users.map(&:name)}"
end

@users = @users.limit(4) # doesn't resolve yet
@users.load # resolves - hence prints loaded: user #1, user #2, ...

0 个答案:

没有答案