# Creating and storing records in Ruby

**URL:** <https://www.ruby-forum.com/t/creating-and-storing-records-in-ruby/100481>\
**Category:** Rails\
**Created:** [July 29, 2006, 6:43am UTC](https://www.ruby-forum.com/t/creating-and-storing-records-in-ruby/100481 "2006-07-29T06:43:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [July 29, 2006, 6:43am UTC](https://www.ruby-forum.com/t/creating-and-storing-records-in-ruby/100481/1 "2006-07-29T06:43:33Z")

</div>

I’ve read through my RoR books and I can’t seem to find the solution.

This is a pretty basic, easy, and practical application for RoR. If you  
guys know of any resources on the net to answer these questions let me  
know.

Question 1:

Basically, I have a many-to-many relationship that I want to add records  
to. I use something like this to add records in the A\_B table:

c.clubs\<\<Club.find\_all\_by\_name(params[:clubs])

This takes the ones that already exist and establishes a relationship  
between A and B.

What if I want to take ones that don’t exist in params[:clubs] and have  
those added to Club table? Is there any shortcut operator for doing that  
AND also does the \<\< operation at the same time? What if I want to add  
another record for a particular instance of A even though there are  
already records in the database. I tried using “\<\<” and got error, since  
it cannot add an entry that already exists. Is there any operation that  
handles this situation?

Question 2

In a one-to-many relationship, where I have a\_id column in my b table,  
how do I take many records that have to go in b and get ActiveRecord to  
either create new entries OR update the ones that exist.

Do I have to find\_all and delete all of them and then reenter them into  
the database. It seems like there would be smarter mechanism in Ruby for  
doing this…
