1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can DataWriter be used for saving multiple records?

Discussion in 'XenForo Development Discussions' started by simunaqv, Dec 8, 2010.

  1. simunaqv

    simunaqv Well-Known Member

    I have a question regarding DataWriter. The save function of DataWriter is used for saving fields in one row of the database table. Is there any mechanism in place for providing field values for several recordsets and then bulk saving?
  2. Lawrence

    Lawrence Well-Known Member

    I read the question two different ways, can you be more specific on what you want to do? If you are setting the same values for each row you can save it to an array and call, for example, $dw->bulkSet($dwInput);
  3. simunaqv

    simunaqv Well-Known Member

    No, I want to save different differernt values in each record.
  4. ragtek

    ragtek Guest

    I think he means, that he want to save MORE entries at once.
    For example:

    $user1 = array('username''pw''mail',...);
    $user2 = array('username2, ...);
    $user3 = array('

    $addusers = array($user1$user2$user3);

    $writer XenForo_DataWriter::create('XenForo_DataWriter_User');
    AFAIK it's not possible.
  5. Shadab

    Shadab Well-Known Member

    This is not possible with DataWriters because they work at row level. They can only be used to add, delete, verify or manipulate data for a single row at a time. If you want to create multiple records using a DataWriter, create a new DW & save() it for each row individually.


    foreach (
    $records as $record)
    $dw XenForo_DataWriter::create('Foo_DataWriter_Bar');



    If you are going to reuse this code heavily in multiple locations (different controllers/actions, for example); you can move it to the corresponding Model. And use the model instead of writing this code over and over.

    $barModel XenForo_Model::create('Foo_Model_Bar');
  6. simunaqv

    simunaqv Well-Known Member

    Thanks Shadab. I will give it a try.

Share This Page