acl9 has_many 通过实现

发布于 2024-11-19 20:30:25 字数 717 浏览 4 评论 0原文

我在 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

I got the following deprecation warning on the rails console:

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.

The issue lies with the roles_users table that I created following an online step-by-step tutorial.

How do I implement a has_many :through association for acl9? It's beyond me, especially since the user and role models each only use helper methods and no actual has_and_belongs_to_many.

This is how they look like:

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

class Role < ActiveRecord::Base
  acts_as_authorization_role
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬シ愛 2024-11-26 20:30:25

后来在这个 GitHub 问题的评论中讨论了答案。

用户模型:

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

角色模型:

acts_as_authorization_role :join_table_name => :roles_users

The answer was later discussed in the comments to this GitHub issue.

User model:

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

Role model:

acts_as_authorization_role :join_table_name => :roles_users
迷路的信 2024-11-26 20:30:25

另外,郑重声明,Rails 决定不再弃用​​ habtm 的 :join_table 选项,因此随着 Rails 的后续补丁版本的发布,该选项就消失了 - 即。如果您只是升级 Rails,则不需要本期中提到的选项。

Also, for the record, Rails decided not to deprecate the :join_table option for habtm after all, so this went away with a subsequent patch release of Rails - ie. you shouldn't need the options mentioned in the issue if you just upgrade your Rails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文