Multiple habtm joins on the same two tables

i have a taskmanager type of project that i am working on, where i need
to separate joins on the same two tables. i need one join for users that
are assigned to the task, and another join for who has read the task, so
they can tell which ones are new.

any suggestions on the best way to accomplish this?

thanks

Hi Josh,

I think you might be able to model this with has_many :through either
one
Model (e.g. UserTaskRelation with two flags: ‘read’ and ‘assigned’ in
it) or
two Models ‘Reading’, ‘Assignation’
User has_many :tasks, :through => :reading
User has_many :tasks, :through => :assignation

with the second approach you are able with the standard created_at,
updated_at to tell when a user did a reading or has been assigned to a
task.

Cheers,
Jan

Jan P. wrote:

Hi Josh,

I think you might be able to model this with has_many :through either
one
Model (e.g. UserTaskRelation with two flags: ‘read’ and ‘assigned’ in
it) or
two Models ‘Reading’, ‘Assignation’
User has_many :tasks, :through => :reading
User has_many :tasks, :through => :assignation

with the second approach you are able with the standard created_at,
updated_at to tell when a user did a reading or has been assigned to a
task.

Cheers,
Jan

thanks for the help

what about the database schema? should the link tables be reading_tasks
and assignation_tasks for those conventions to work?

Jan P. wrote:

Hi Josh,

I think you might be able to model this with has_many :through either
one
Model (e.g. UserTaskRelation with two flags: ‘read’ and ‘assigned’ in
it) or
two Models ‘Reading’, ‘Assignation’
User has_many :tasks, :through => :reading
User has_many :tasks, :through => :assignation

with the second approach you are able with the standard created_at,
updated_at to tell when a user did a reading or has been assigned to a
task.

This is sort of backwards. I think you want to have one join model and
two associations going through it.

User:
has_many :assignments
has_many :assigned_tasks, :through => :assignments, :class_name =>
“Task”
has_many :read_tasks, :through => :assignments, :class_name => “Task”

You can read more about this approach here:
http://blog.hasmanythrough.com/articles/2006/05/06/through_gets_uniq


Josh S.
http://blog.hasmanythrough.com/

Hi Josh,

no for the through association you don’t need a solely join table of the
kind of comments_posts. Instead you’ve got a full featured model (and
its
underlying table like ‘readings’) wich might grow with your application
and
it’s growing needs and is even able to be handled in the great way of
the so
called restful or crud controllers. Do a little research on ‘has_many
:through’ as well as restful and you’ll get the idea. HABTM has it’s use
cases but a full ‘through-model’ has so many advantages especially for
cases
like yours.

Cheers,
Jan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs