1

내 설정 : 내 응용 프로그램 LogedIn - 사용자에은 다 대다 : has_many : 레일 통해 사용자 테이블 관계 문제는 모델 4

class Doctor < ActiveRecord::Base 
    has_many :appointments 
    has_many :patients, :through => :appointments 
end 

class Appointment < ActiveRecord::Base 
    belongs_to :doctor 
    belongs_to :patient 
end 

class Patient < ActiveRecord::Base 
    has_many :appointments 
    has_many :physicians, :through => :appointments 
end 

는 하나 의사, 환자 또는 내가 가진 관리자입니다 이해하는 방법을 의사와 약속 환자 관계의 작동하지만이 설정하는 방법에 대한 사용자 모델과 테이블이

class User_type < ActiveRecord::Base 
    belongs_to :doctors, class_name: "USER" 
    belongs_to :patients, class_name: "USER" 
end 

에 내가 여기에 중요한 자기 연결을 잃었 알고하지만 난 그렇게 할, 또는 수있는 방법을 다른 방법 이를 위해이 모델과 테이블을 설정해야합니다. 미리 감사드립니다.

답변

0

여기에 오타가 있습니다 class User_type < ActiveRecord::Base belongs-to :doctors, class_name: "USER" belongs_to :patients, class_name: "USER" end

belongs_to해야합니다, 당신이 있는지 그게 전부가 아니라 문제?

+0

나는 오타를 바로 잡았지만 내 실제 질문은 모델과 테이블에 관한 것입니다. 사용자 (들)는 어떻게 보일까요? –

2
class User < ActiveRecord::Base 
    has_one :doctor 
    has_one :patient 
end 

class Doctor < ActiveRecord::Base 
    belongs_to :user 
    has_many :appointments 
    has_many :patients, :through => :appointments 
end 

class Appointment < ActiveRecord::Base 
    belongs_to :physician 
    belongs_to :patient 
end 

class Patient < ActiveRecord::Base 
    belongs_to :user 
    has_many :appointments 
    has_many :physicians, :through => :appointments 
end 

많은 희망을 잘 이해한다면 희망적입니다.

+0

의사 또는 환자는 그들 자신이 사용자입니다. 그 사이에 어떻게 많은 수의 관계가있을 수 있습니까? 가능한? –

+0

사용자는 의사 또는 환자 여부에 관계없이 사용자입니다. 둘 다 사용자에게 속합니다. –

+0

그러면 로그인 사용자는 자신의 역할을 어떻게 알 수 있습니까? –