【问题标题】:Getting has_many through models using Rails使用 Rails 通过模型获取 has_many
【发布时间】:2015-10-27 16:25:21
【问题描述】:

我目前正在使用这个

获得 User 模型的 has_many 关系关联
User.reflect_on_all_associations(:has_many)

现在,我怎样才能通过 has_many 通过 关联获得 User 模型

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4


    【解决方案1】:

    如果你只想要has_many :through 关联,你可以像这样过滤你的数组:

    User.reflect_on_all_associations(:has_many).select do |association|
      association.options.key? :through
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 2016-07-24
      • 2014-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多