2012-05-18 2 views
0

는이 코드가 있습니다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 

을하고 나는이 쓰기, 또는이 경우 가장 effecient 방법은 다른 방법을 알고 싶습니다. 나는 사용자 모델의 범위를 생각하고 있었다. 어떤 아이디어?

+0

http://codereview.stackexchange.com이 더 나은 곳이 될 것입니다. –

답변

6

나는 User의 범위로 regularemployee를 작성합니다

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 
관련 문제