मैंने जो कुछ भी चाहते हैं उसे दबा दिया है, लेकिन मुझे ऐसा लगता है कि रेल डिजाइनर की तलाश में नहीं है। मूल रूप से, मेरे पास है (pluralization अलग सेट कृपया/आदि मुद्दों):हैस_Many: के माध्यम से या: finder_sql
मानव रिश्ते (जनक, वंश)
मैं एक एकल अभिभावक के लिए सभी offsprings पाने के लिए कोशिश कर रहा हूँ और कई के लिए एकल अभिभावक संतान (प्रति अपराध केवल एक माता पिता मानते हैं)।
मैं मॉडल में निम्नलिखित तरीके से ऐसा कर सकते हैं:
has_one :parent, :through => :relationships, :foreign_key => :human_id, :source => :source_human
has_many :offsprings, :finder_sql =>
'SELECT DISTINCT offsprings.* ' +
'FROM humans offsprings INNER JOIN relationships r on ' +
'r.human_id = offsprings.id where r.source_human_id = #{id}'
मैं अच्छे तरह से यह करने के लिए है क्योंकि यह करने के लिए किया था,:
has_many :offsprings, :through => :relationships, :foreign_key => :source_human_id, :source => :human
संभव नहीं है क्योंकि विदेशी कुंजी has_many में अनदेखा किया गया है (यहां दस्तावेज़ों के अनुसार: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many)
हालांकि, अब मुझे यह त्रुटि मिल रही है:
DEPRECATION WARNING: String-based interpolation of association conditions is deprecated. Please use a proc instead. So, for example, has_many :older_friends, :conditions => 'age > #{age}' should be changed to has_many :older_friends, :conditions => proc { "age > #{age}" }. (called from irb_binding at (irb):1)
हालांकि, कोई फर्क नहीं पड़ता कि मैं कैसे हैक करता हूं: यहां स्थितियां, ऐसा नहीं लगता है: finder_sql भाग लेना चाहता है। कोई विचार?
एक विजेता देवियो और रोगाणु। दस्तावेज़ यहां गलत हैं, आप ऐसा नहीं करते हैं: finder_sql पर स्थितियां, आप इसे अभी बनाते हैं। – aronchick