Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Batch Insert using ORM
  • Just confirming, if i'm batch inserting using the ORM ill have to use a foreach() loop for the $model->save() process right?
    $batch = array();
    
    foreach(Input::post('threads') as $threads)
    {
        $thread = new Model_Thread(array(
            'title'  => $threads['title'],
            'cat'    => $threads['cat'],
            'date'   => time(),
        ));
    
        //related models
    
        $batch[]    = $thread;
    }
    
    
    foreach($batch as $thread)
    { 
        $thread->save()
    }
    
  • Harro Verton wrote on Saturday 11th of June 2011:
    Yes, the ORM is made for object interaction. Don't try to force all database I/O through an ORM model. In some cases it's a lot more efficient to simply use DB calls. If you insist, then yes, you'll have to create ORM model objects in a loop, and save them one at the time.

    Thanks, in this case its not really a batch like 100+ or something, just 2-3 for updating a bunch of threads or posts. So that's why i'm using the ORM. Thanks again.
  • Yes, the ORM is made for object interaction. Don't try to force all database I/O through an ORM model. In some cases it's a lot more efficient to simply use DB calls. If you insist, then yes, you'll have to create ORM model objects in a loop, and save them one at the time.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion