【问题标题】:Retrieving name of a :through table from an association?从关联中检索 :through 表的名称?
【发布时间】:2015-08-11 13:37:53
【问题描述】:

我有通过has_many :through => join_table 相互连接的表。

我正在尝试创建一个需要将 2 个表名作为输入并能够获得上述join_table 的实际名称。

我在想一些事情(例如,使用表 usersgroups),例如:

 users.groups.joiner

我一直在四处寻找,但还没有找到任何东西。这个可以吗?

【问题讨论】:

    标签: ruby-on-rails associations has-many-through has-many


    【解决方案1】:

    在 TableA 的类模型上调用 reflections 方法。然后使用 TableB 的名称来导航哈希,就像这里接受的答案一样:(How to get activerecord associations via reflection)。

    进行操作,直到获得 TableA 和 TableB 的 :through 反射值。

    【讨论】:

      猜你喜欢
      • 2015-01-15
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多