[英]Is there another way to write this in Ruby on Rails?
我有以下代碼:
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
我想知道另一種寫此方法的方法,或者這是否是最有效的方法。 我在考慮用戶模型中的范圍。 有任何想法嗎?
我將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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.