RAILS: How to get has_many associations of a model

后端 未结 3 419
猫巷女王i
猫巷女王i 2020-12-10 01:46

how I can get the has_many associations of a model?

For example if I have this class:

class A < ActiveRecord::Base
  has_many B
  has_many C
end
<         


        
3条回答
  •  情书的邮戳
    2020-12-10 02:13

    Found the solutions:

    def self.get_macros(macro)
      res = Array.new
      self.reflections.each do |k,v|
        res << k if v.macro == macro.to_sym
      end
      return res
    end
    

提交回复
热议问题