如何检查模型的关联是否依赖于另一个

时间:2013-06-08 13:13:23

标签: ruby-on-rails-3 console associations model-associations

我想调试一个凌乱的应用程序,我希望看到有效的模型配置

有没有办法从关联方面了解哪些铁路知道模型?

例如 - 如果我有

class User

has_many :comments, :dependent => :destroy

end

我想看看rails知道如果在用户控制器中调用destroy动作,它将在注释控制器中调用destroy动作

有没有办法在rails控制台中查看?

1 个答案:

答案 0 :(得分:2)

得到它,

可以用

完成
User.reflections

导致

 :comments=>
  #<ActiveRecord::Reflection::AssociationReflection:0xc52abc8
   @active_record=
    User(id: integer, ...)
   @collection=true,
   @macro=:has_many,
   @name=:comments,
   @options={:dependent=>:destroy, :extend=>[]},
   @plural_name="comments">

正如您所看到的,它为您提供关联类型(has_many),所谓的(:注释),选项和复数名称。

我在:爱:用这种方法:)