0
그룹 및 : uniq 태그가 컬렉션 정의를 통해 has_many에 대한 옵션으로 문제가 있습니다. 내 시스템에서 정의 된 많은 트리플 모델 연결이 있고 (실제) 반복을 피하기 위해 그룹화 된 요소를 나열하고 싶습니다. 내 주요 모델은 다음과 같습니다컬렉션을 통해 has_many 그룹화 문제가 발생했습니다.
class Trip < ActiveRecord::Base
belongs_to :agent
has_many :trips_destinations, :class_name => "TripsDestination"
has_many :destinations, :through => :trips_destinations
has_and_belongs_to_many :vibes, join_table: :trips_vibes
has_and_belongs_to_many :verbs, join_table: :trips_verbs
has_many :trips_destinations_activities, :class_name => "TripsDestinationsActivity"
has_many :activities, :through => :trips_destinations_activities, :uniq => true
has_many :trips_destinations_hotels, :class_name => "TripsDestinationsHotel"
has_many :hotels, :through => :trips_destinations_hotels
has_many :trips_destinations_recommended_places, :class_name => "TripsDestinationsRecommendedPlace"
has_many :recommended_places, :through => :trips_destinations_recommended_places
has_many :trips_destinations_transportations, :class_name => "TripsDestinationsTransportation"
has_many :transportations, :through => :trips_destinations_transportations
...
...
end
사람은 왜 쌍 [trip_id, destination_id] 주어진 반복을 피하는 나열하는 방법을 알아? 왜 반복 되는가?
내 레일 버전이 4이고 아래 이미지는 그룹화 옵션을 has_many 관계에 전달할 때의 오류 메시지를 보여줍니다.
도와주세요! 레일 4.
has_many :activities, -> { uniq }, :through => :trips_destinations_activities
고유 지금 scope syntax을 가지고위한
감사합니다. @eabraham. 당신은 채팅, 스카 이프 같은가요? 이 문제를 해결했지만 지금은 트리플 모델 연관성에 대한 의문을 가지고 있습니다. – halbano
트리플 모델은 다 대다 관계를 의미합니까? 그렇다면 [this] (http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association)와 같이 모델링 해보십시오. – eabraham
답장을 보내 주셔서 감사합니다. 트리플 모델 협회에 의해 나는 3 개의 다른 모델에 대한 링크를 가지고있는 모델을 이해한다. 그런 식으로 DB에 모델링 : trip_id | destination_id | activity_id. 나는 당신이 가이드에서 제안하는 것처럼 이것을 모델링하고있다. 그러나 나는 일하는 어떤 것을 얻을 수 없다. – halbano