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.

Data Model Questions /

Multiple inserts using the DataModel


Reply


3 Posts   1623 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