# Question about multi-table creates

**URL:** <https://www.ruby-forum.com/t/question-about-multi-table-creates/72999>\
**Category:** Rails\
**Created:** [October 20, 2006, 3:00pm UTC](https://www.ruby-forum.com/t/question-about-multi-table-creates/72999 "2006-10-20T15:00:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 20, 2006, 3:00pm UTC](https://www.ruby-forum.com/t/question-about-multi-table-creates/72999/1 "2006-10-20T15:00:07Z")

</div>

Little unsure how to get started on this one.

In my form there are fields for various tables.  
There is a main table/model. So the additional tables relate to the  
main  
one. Better I show an example:

User model: Color model:  
id = 1 id = 1 | user\_id = 1 | color = blue  
id = 3 | user\_id = 1 | color = red  
id = 10 | user\_id = 1 color = green

So in other words when the user fills in the form, because they may  
select  
multiple colors, new rows are created in the Color model, but all must  
have the corresponding user\_id.  
I understand the table relationships, but wonder how the create happens.  
Do  
I need to use “transactions” or just a regular create? I think I can  
stuff  
all the colors into a hash ?  
Anyway, any suggestions would be greatly appreciated.

Stuart

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 20, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/question-about-multi-table-creates/72999/2 "2006-10-20T19:00:41Z")

</div>

Hi Stuart -

I would just create the color / user records in the controller. I’m not  
sure transactions can be used across models. (anyone know better?).

Starr

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 20, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/question-about-multi-table-creates/72999/3 "2006-10-20T21:27:16Z")

</div>

On 10/20/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> id = 10 | user_id = 1 color = green
> 
> ```
> 
> –  
> [Dark ambient - Wikipedia](http://en.wikipedia.org/wiki/Dark_ambient)

Anyone ? The main thing at this point I’m trying to visualize is getting  
the  
multiple entries into the additional table.

## Stuart

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...
