From: Paul Lutus Date: 2006-11-21T02:05:07+09:00 Subject: Re: Inserting multiple rows from array David Lelong wrote: > Hi, > > I have two sets of values: > > job.id = 1 and contact_ids = [4, 8] > > I want to be able to iterate over all of values in the contact_id array > and create database records consisting of a job_id and contact_id. > > So, in this example, the end result would be two new records that > contain: > > -------------------- > |job_id |contact_id| > -------------------- > | 1 | 4 | > -------------------- > | 1 | 8 | > -------------------- > > Any advice? 1. Create an array of records, each a field array containing the job IDs and the respective contact IDs. 2. Submit the array to the database in a way that the database understands. Did you want specific Ruby code to accomplish this? If so, just say so. record_array = [] job_id = 1 contact_id.each |id| do record_array << [ job_id, id ] end In order to take the next step, we'll need more information, like, what database? -- Paul Lutus http://www.arachnoid.com