# Managing joins

**URL:** <https://www.ruby-forum.com/t/managing-joins/91922>\
**Category:** Rails\
**Created:** [April 13, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/managing-joins/91922 "2007-04-13T14:27:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@seeah](https://www.ruby-forum.com/u/seeah)\
**Post date:** [April 13, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/managing-joins/91922/1 "2007-04-13T14:27:23Z")

</div>

Hi there,

Another rails newbie here, trying to get started on some many to  
many :through structures (solid background in dB, php and asp). On  
the database and model side of things, everything is relatively  
clear. However, when it comes to the interactions on the web  
interface, I’m still not getting something.

I’ve seen a lot of good examples for _adding_ items that are linked  
to an existing item in another table, and others for creating  
multiple related items in one shot. However, what I haven’t yet  
found is the means to link existing objects together via a join  
table. It will definitely be a join table rather an a  
has\_many\_and\_belongs\_to since there will be some additional data held  
in the join table.

The simplified use case looks something like this :

[http://homepage.mac.com/eableson/xfer/simple\_use\_case.jpg](http://homepage.mac.com/eableson/xfer/simple_use_case.jpg)

So I have people creating projects and consultants in their own  
independent tables (and models and controllers). Project planners  
need to assign consultants to projects and then assign timeblocks  
(managed in 1/2 day increments) which will be linked to both the  
consultant and the project.

Focussing on the consultant to project links I have the following (I  
still haven’t worked out the tertiary join for the timeblocks to both  
missions and consultants):  
class Consultant \< ActiveRecord::Base  
has\_many :timeblocks  
has\_many :missions  
end

class Assignment \< ActiveRecord::Base  
belongs\_to :consultant  
belongs\_to :mission  
end

class Mission \< ActiveRecord::Base  
has\_many :consultants  
has\_many :timeblocks, :through =\> :consultants  
end

The project planner will pull up a project page, and assign a  
consultant (potentially adding several) to the project. Under the  
project information, each assigned consultant will be displayed, and  
a calendar with selecting timeblocks as checkboxes so that I can pick  
the dates he’ll be working on the project. Something like:

[http://homepage.mac.com/eableson/xfer/webpage\_models.jpg](http://homepage.mac.com/eableson/xfer/webpage_models.jpg)

I was thinking of having a select list with an add button to build  
the association, but I haven’t figured out how to build the necessary  
rhtml code to handle this. If I were working at a lower layer in  
php, I know exactly how I would accomplish this, but I’m still have a  
few difficulties in finding the appropriate Rails abstraction to  
express this.

Hints, tips?

Erik A.
