Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple inserts using the DataModel


Go to End


3 Posts   2626 Views

Avatar
glenrobertson

Community Member, 1 Post

22 August 2009 at 10:55am

Is there a way to insert multiple records into the database as one query, using the DataModel (without having to write a raw SQL query) ?

For example, at the moment I am doing this:

$member = new Member();
$organization->Name = $data['member_name_0'];
..
$member->write();

$member = new Member();
$organization->Name = $data['member_name_1'];
..
$member->write();

.. which I'm guessing it would be performing multiple insert queries, but it would be better to do a single insert query for all the records. Hope that makes sense.

Any help appreciated,
Cheers

Avatar
Hamish

Community Member, 712 Posts

24 August 2009 at 2:07pm

Are you trying to import a list of members into your database?

There is an abstract class designed for bulk updates of data - at the moment I think it is only subclassed by CsvBulkLoader. This is a good way to import a large amount of data.

However, it will still insert/update on a line by line basis. If the question is performance related, it sounds like you are looking for a way to queue up changes into a single transaction. That would be great, but AFAIK there is no functionality for this at present.

Hamish

Avatar
imsas

Community Member, 22 Posts

28 August 2009 at 12:47am

If i understood good problem seem, I found solution http://silverstripe.org/data-model-questions/show/267209?showPost=267743