acl9 has_many through implementation

437 Views Asked by At

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
2

There are 2 best solutions below

0
On BEST ANSWER

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
0
On

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.