【问题标题】:acl9 has_many through implementationacl9 has_many 通过实现
【发布时间】:2011-10-05 12:47:23
【问题描述】:

我在 Rails 控制台上收到以下弃用警告:

DEPRECATION WARNING: Having additional attributes on the join table of a 
has_and_belongs_to_many association is deprecated and will be removed in Rails 3.1. 
Please use a has_many :through association instead.

问题在于我根据在线分步教程创建的roles_users 表。

如何为 acl9 实现 has_many :through 关联?这超出了我的范围,特别是因为 userrole 模型都只使用辅助方法,而没有实际的 has_and_belongs_to_many

这就是它们的样子:

class User < ActiveRecord::Base
  acts_as_authentic
  acts_as_authorization_subject  :association_name => :roles
end

class Role < ActiveRecord::Base
  acts_as_authorization_role
end

【问题讨论】:

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


【解决方案1】:

这个 GitHub 问题的 cmets 稍后讨论了答案。

用户模型:

acts_as_authorization_subject :association_name => :roles, :join_table_name => :roles_users

榜样:

acts_as_authorization_role :join_table_name => :roles_users

【讨论】:

    【解决方案2】:

    另外,为了记录,Rails 决定毕竟不弃用 habtm 的:join_table 选项,所以这随着 Rails 的后续补丁版本而消失 - 即。如果您只是升级 Rails,则不需要问题中提到的选项。

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多