[英]acl9 has_many through implementation
I got the following deprecation warning on the rails console:我在 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.
The issue lies with the roles_users
table that I created following an online step-by-step tutorial.问题在于我按照在线分步教程创建的
roles_users
表。
How do I implement a has_many:through
association for acl9?如何为 acl9 实现
has_many:through
关联? It's beyond me, especially since the user
and role
models each only use helper methods and no actual has_and_belongs_to_many
.这超出了我的范围,特别是因为
user
和role
模型都只使用辅助方法而没有实际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
The answer was later discussed in the comments to this GitHub issue.稍后在此 GitHub 问题的评论中讨论了答案。
User model:用户 model:
acts_as_authorization_subject :association_name => :roles, :join_table_name => :roles_users
Role model:角色 model:
acts_as_authorization_role :join_table_name => :roles_users
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.此外,为了记录,Rails 决定毕竟不弃用 habtm 的
:join_table
选项,所以这随着 Rails 的后续补丁版本而消失 - 即。 you shouldn't need the options mentioned in the issue if you just upgrade your Rails.如果您只是升级 Rails,则不需要问题中提到的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.