How can I find a model's relationships?

前端 未结 1 1110
情深已故
情深已故 2021-01-01 12:31

I want to, when given a particular model, return all the related models it is associated with. For example:

class Dog < ActiveRecord::Base
  has_many :bo         


        
相关标签:
1条回答
  • 2021-01-01 13:28
    Dog.reflect_on_all_associations
    

    http://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html#M001405

    You wouldn't do this on an instance but on the model itself.

    0 讨论(0)
提交回复
热议问题