我有有許多設施查詢相結合的記錄
一個鏈模型我有一個公司模型有很多company_mappings。通過company_mappings一個北美經銷商可以有很多設施,無論是通過鏈或直接從設施,他們都通過在多態關聯companies_mapping模型。
的Company_Mapping模型
belongs_to :company
belongs_to :company_associations, polymorphic: true
的鏈模型
has_many :company_mappings, as: :company_associations
has_many :facilities
的設施模型
has_many :company_mappings, as: :company_associations
belongs_to :chain
現在我有公司模型有兩個不同的查詢來獲得其相關設施。我想有一個查詢獲取從公司
的公司模型相關聯的所有設施
has_many :company_mappings
has_many :chains, through: :company_mappings, source: :company_associations, source_type: "Chain"
has_many :facilities, through: :company_mappings, source: :company_associations, source_type: "Facility"
has_many :facilities_from_chains, through: :chains,source: :facilities, class_name: 'Facility'
我想設施相結合和_facilities_from_chains_成一個單一的查詢或能以某種方式合併它們。我嘗試使用.merge,但是出現錯誤。
謝謝@jon,但即時通訊尋找回活躍的記錄關係。如果我能找到一種方法,我也會自己試着回答 – coderVishal