我有一个模型。现在我需要从控制台相同的所有关联的细节。
User.reflect_on_all_associations
这将返回一系列类似于以下内容的关联:
#<ActiveRecord::Reflection::AssociationReflection:0x00000105575548 @macro=:has_many, @name=:posts, @options={}, @active_record=User(id: integer, login: string), @collection=false>
样本代码:
reflections = User.reflect_on_all_associations
reflections.each do |reflection|
puts ":#{reflection.macro} => :#{reflection.name}"
end