Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Multiple inserts using the DataModel

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

Page: 1
Go to End
Author Topic: 1554 Views
  • glenrobertson
    Avatar
    Community Member
    1 Post

    Multiple inserts using the DataModel Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Multiple inserts using the DataModel Link to this post

    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

  • imsas
    Avatar
    Community Member
    22 Posts

    Re: Multiple inserts using the DataModel Link to this post

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

    1554 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.