activerecord question

M

Mohammad Khan

------=_Part_15462_765849.1127490566683
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

My piece of code is below, (consider Country is subclass ActiveReocrd::Base=
)

File.open("country.list").each do | line |
line.strip!
name, code =3D line.split("\t")

c =3D Country.new
c.name <http://c.name> =3D name
c.code =3D code
c.save
end

This piece of code is inserting rows in countries table.
and the number of insert statement is equal to the number of lines in
country.list

Is there any way to save those rows by one method.
What I want is not to send 100 insert statement to database server, I want
to send only one insert statement in database server.


Thanks
Mohammad Khan

------=_Part_15462_765849.1127490566683--
 
E

Eric Hodel

My piece of code is below, (consider Country is subclass
ActiveReocrd::Base)

File.open("country.list").each do | line |
line.strip!
name, code = line.split("\t")

c = Country.new
c.name <http://c.name> = name
c.code = code
c.save
end

This piece of code is inserting rows in countries table.
and the number of insert statement is equal to the number of lines in
country.list

Is there any way to save those rows by one method.
What I want is not to send 100 insert statement to database server,
I want
to send only one insert statement in database server.

http://lists.rubyonrails.org/mailman/listinfo/rails

Has your answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,212
Latest member
BrennaCaba

Latest Threads

Top