tying table

Hey,

The table you call a 'tying' table is also called a 'join' table. It is part of what it is known as a 'has and belongs to many' relationship. The good news is that Rails handles this very easily.

Let's take the Organizations - Addresses relationship. First you'll create your models and tables. You'll end up with these tables: organizations addresses

Then you need to create the join table:

addresses_organizations

Well you kinda need to write the code to add the address. It'd look something like this:

Let's say you've got an 'add address' form and it posts to an action that you want to add the address to an existing organization:

# Create and validate the new address address = Address.new(params[:address])

if address.save    # Find the existing organization    organization = Organization.find_by_id(params[:organization_id])

   # Associate the address with this organization    organization.addresses << address end

Obviously there's a lot more to getting it to work than that code, but I hope it demonstrates the concept.

Steve