0

현재 Rails를 배우므로 친절하십시오. 우리의 '고객'에 로그인 할 수있는 응용 프로그램을 구축Rails 3.0 has_many 및 belongs_to 연관 두통.

및 견적 작성 :

는 내가 지금까지 가기 전에 내가이 권리를 얻고 있는지 확인하고 싶습니다. '공급자'(이 경우 회의 장소 소유자)는 견적을보고 고객이 볼 수있는 제안서를 사용하여 회신 할 수 있습니다. 각 공급 업체 계정에는 하나 이상의 '장소'가 포함될 수 있습니다 (예 : 장소 체인을 운영하는 경우). 각 제안은 특정 장소에서 제공됩니다.

다른 복잡한 문제는 나중에 다룰 것입니다. 관계가 보이는 한이 모양이 올바른 것입니까?

P.S 나는 아래 코드가 실제로 작동하는 코드가 아니라는 것을 알고 있습니다. 나는 그 주위에 머리를 얻으려고 시도하는 동안 이것을 내 놓았습니다.

Customer (will be a type of user) 
has_many :quotes 
has_many :proposals, :through => :venue 

Supplier (will be a type of user) 
has_many :venues 
has_many :proposals, :through => :venue 

Venue 
belongs_to :supplier 
has_many Proposals 

Quote 
belongs_to :customer 

Proposal 
belongs_to :venue 

그리고 기본 테이블 :

Customer 
    id 

Supplier 
    id 

Quote 
    id 
    customer_id 

Venue 
    id 
    supplier_id 

Proposal 
    id 
    venue_id 

등 has_ones와 has_and_belongs_to_many를 사용하여이 작업을 수행하는 더 나은 방법이있을 수 있습니다,하지만 난 아무 생각도 없어.

감사

+0

은 어떻게할까요''고객이'와 관련이있는 것으로 장소? 왜냐하면 '고객'이 '장소'를 통해 많은 제안을하기를 원한다면 고객은 또한 많은 장소를 가져야하기 때문이다. –

+0

고객은 모든 장소에서 제안서를 수령 할 수 있습니다. 그 둘을 모두 없앨 수 있습니까? –

+0

그래서 적어도'Customer has_many : proposals'에서': through'를 제거해야합니다. 당신의'공급자 '가 제안과 어떻게 연결되기를 원하십니까? –

답변

0

좋아, 그래서 나는 다음과 같이해야한다고 생각 :

Customer 
    has_many :quotes 
    has_many :proposals 

Supplier 
    has_many :venues 
    has_many :proposals, :through => :venues 

Venue 
    belongs_to :supplier 
    has_many :proposals 

Quote 
    belongs_to :customer 

Proposal 
    belongs_to :venue 
    belongs_to :customer 

및 DB 스키마의

:

Customer 
    id 

Supplier 
    id 

Quote 
    id 
    customer_id 

Venue 
    id 
    supplier_id 

Proposal 
    id 
    venue_id 
    customer_id