Mat*_*iby 0 scope ruby-on-rails ruby-on-rails-3
我有这个代码:
class Company < ActiveRecord::Base
has_many :users, :through => :company_users do
def regular
where('regular_user = ?', true)
end
def employee
where('regular_user = ?', false)
end
end
Run Code Online (Sandbox Code Playgroud)
我想知道另一种写这种方式,或者这是最有效的方法.我在考虑用户模型中的范围.有任何想法吗?
我会写regular和employee作为范围User:
class Company < ActiveRecord::Base
has_many :users, :through => :company_users
end
class User < ActiveRecord::Base
scope :regular, where(:regular_user => true)
scope :employee, where(:regular_user => false)
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |