मैं तीन मॉडलों, उन सभी को निम्न संघों होने हैस्थापना एक: has_many: एक belongs_to संघ रूबी पर संघ के माध्यम से ऑन रेल्स
class Model1 < ActiveRecord::Base
has_many :model2s
has_many :model3s
end
class Model2 < ActiveRecord::Base
belongs_to :model1
has_many :model3s, :through => :model1 # will this work? is there any way around this?
end
class Model3 < ActiveRecord::Base
belongs_to :model1
has_many :model2s, :through => :model1 # will this work? is there any way around this?
end
आप टिप्पणी की पाठ में देख सकते हैं, मैं उल्लेख किया है कि मैं क्या जरूरत है ।
प्रतिनिधिमंडल भाग मुझे यह त्रुटि देता है "प्रतिनिधिमंडल को एक लक्ष्य की आवश्यकता है। अंतिम विकल्प के रूप में कुंजी के लिए एक विकल्प हैश की आपूर्ति करें (उदा। प्रतिनिधि: हैलो,: से =>: ग्रीटर)।" मुझे विधि भाग – Rohit
आज़माएं, पहला तरीका अच्छा कर रहा है और मेरी समस्या हल करता है। लेकिन कृपया प्रतिनिधिमंडल तंत्र में कुछ बदलाव ढूंढें और जवाब संपादित करें। : डी – Rohit
प्रतिनिधि का उपयोग करें: model3s,: to =>: प्रतिनिधि 1 के बजाय model1: model3s,: as =>: model1। : डी मेरे लिए काम करता है – Rohit