Displaying 1 result from an estimated 1 matches for "companies_packages".
2005 Dec 15
2
efficient INSERTS
...Company
Package
with a habtm relationship.
In my controller, I have a ''dispatch'' action which does the following
@companies.each do |company|
@packages.each do |package|
company.packages.push_with_attributes(package, :sent_on => Time.now)
end
end
my table ''companies_packages'' therefore lists which company was sent which
package at what time.
If I''m sending 20 packages to 20 companies though, I generate 400 INSERT
statements. Is there a rails way of doing this more efficiently?
i.e. generating an SQL statement like
INSERT INTO `companies_packages` (...