acl9 has_many 通过实现
我在 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
关联?这超出了我的范围,特别是因为 user
和 role
模型都只使用辅助方法,而不使用实际的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
后来在这个 GitHub 问题的评论中讨论了答案。
用户模型:
角色模型:
The answer was later discussed in the comments to this GitHub issue.
User model:
Role model:
另外,郑重声明,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.