Topic: Rails 3 way HABTM Join advice needed

A little history:

I am modifying an existing app.
Now requirements are: Users have access to the job by role(s) in the job.

Looks to be many to many relations in this case.
HABTM setup with 3 way join table (job_id, role_id, user_id) here --

  User: class User < ActiveRecord::Base   
has_and_belongs_to_many :roles, :join_table => "jb_join_table"   has_and_belongs_to_many :jobs, :join_table => "jb_join_table"
  Job: class Job < ActiveRecord::Base     
has_and_belongs_to_many :roles, :join_table => "jb_join_table"          has_and_belongs_to_many :users, :join_table => "jb_join_table"

  Role: class Role < ActiveRecord::Base   
has_and_belongs_to_many :users, :join_table => "jb_join_table"   has_and_belongs_to_many :jobs, :join_table => "jb_join_table" I am not sure what all this buys me....

I realize I will have to manage the join table myself in the app. (Add/delete)

If I want to CRUD each model, what would my calls look like?

Typical use path:

Users exist already

Create Job and Add Users to Job with Roles. (thinking this is a tricky HABTM checkbox)

Update User list/roles

I have searched a fair bit without finding something like this.
Surely someone has crossed this bridege before smile
I've looked at CANCAN but do not understand how it would work with a 3 way like this.
I think I am missing a lot here sad

I'd really appreciate your expertise/help. Thanks!

Last edited by habumaster (2011-04-01 12:23:14)