実行時に ActiveRecord クラスの関連付けを見つけたいのですが...
私が次のものを持っているとしましょう:
class Person < ActiveRecord::Base
has_many :chairs
has_many :pens
end
class Chair < ActiveRecord::Base
belongs_to :person
end
class Pen < ActiveRecord::Base
belongs_to :person
end
Person が "多くの" 椅子とペンを持っていること、およびその逆を実行時に確認するにはどうすればよいですか? 文字列の配列を返すメソッドを探しています (そのようなメソッドが存在する場合)。すなわち
Person.has_many_assocations
戻ります:
["chairs", "pens"]
と
Pen.belongs_to_associations
戻ります:
["person"]
存在するこのようなメソッドがありませんか??
ご協力いただきありがとうございます。