# Has\_many before saving record

**URL:** <https://www.ruby-forum.com/t/has-many-before-saving-record/106248>\
**Category:** Rails\
**Created:** [June 7, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/has-many-before-saving-record/106248 "2007-06-07T21:09:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [June 7, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/has-many-before-saving-record/106248/1 "2007-06-07T21:09:22Z")

</div>

I am currently creating a small app that can be simplified as follows:

An Album that has\_many AlbumTracks  
An AlbumTrack that belongs\_to an Album

The user will create a new album - that is - not currently saved in  
the database.  
They will then add tracks to the album with an inline form that will  
update the existing display, appending the track to the list of  
tracks.

It is important that the Album record has not yet been saved for  
usability purposes, as the user may decide to abort the creation,  
which could be as simple as closing their browser, and incomplete  
albums should not be stored in the database.

Additionally, during track insertion, the user must be able to reorder  
the tracks, using the sortable\_element scriptaculous helper. Again  
before the saving of the record.

My thoughts on implementing this have been to use a session array to  
store the track listings in, and then copying this tracklist array to  
the main Album object on save/update. Is this the best way to achieve  
this?

I am aware that I could simply use an html text\_field array, which  
would be fine for the initial insertion of the content, but could  
potentially cause problems on an edit, whereby certain Tracks may have  
been allocated an ID in the database from a previous save, and new  
Tracks will not have an allocated ID.

Does anyone have any thoughts on this, or better still - a  
solution! 🙂

Kind Regards,

Matt

p.s. the actual webapp is not an album and tracklist project, but that  
is probably the simplest way I can describe my requirement - please  
dont point me to the album/tracklist howto, as its not relevant!
