【发布时间】:2013-08-04 14:52:36
【问题描述】:
假设我有两个模型
class Client < ActiveRecord::Base
has_many :accounts
end
class Account < ActiveRecord::Base
belongs_to :client
end
现在,我想要一种方便的方法来访问已批准的帐户(:approved => true)。 什么更好用,为什么?
-
has_many: approved_accounts, -> { where :approved => true }为Client型号
或
-
scope: approved, -> { where :approved => true }代表Account型号
【问题讨论】:
标签: ruby-on-rails