Adam Akhtar wrote:
> If i create in memory a hundred or so instances of a model, how do i go
> about saving them to the database.
> 
> I have a Task Model
> 
> and say I have an array of Task obects
> 
> @tasks = [...]
> 
> how do i save them
> 
> do i
> 
> @tasks.each do |task|
> task.save
> end
> ?

What you can do is use the Model#create class method. You will have to 
instantiate hashes of properties instead of model objects, though. Like:

tasks = [{:name => 'Go shopping', :date => Time.now},{:name => 'Get a 
haircut' => 1.day.from_now}] #etc
Task.create(tasks)
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to