Is there a way to list all belongs_to associations?

后端 未结 3 454
悲哀的现实
悲哀的现实 2020-12-13 06:21

I need to list all belongs_to associations in a model object and iterate through them. Is there a way to do this?

3条回答
  •  盖世英雄少女心
    2020-12-13 06:46

    You can make use of reflect_on_all_associations method from Reflection For example:

    Thing.reflect_on_all_associations(:belongs_to)
    

提交回复
热议问题