示例#1
0
 /**
  * Method to test save().
  *
  * @return void
  *
  * @covers Windwalker\DataMapper\AbstractDataMapper::save
  */
 public function testSave()
 {
     $dataset = array(array('title' => 'Sunflower', 'catid' => 5), array('id' => 15, 'title' => 'striped2', 'catid' => 5));
     $returns = $this->instance->save($dataset, 'id');
     $returns = new DataSet($returns);
     $newDataset = $this->loadToDataset('SELECT * FROM ww_flower WHERE catid = 5');
     $this->assertEquals(array(97, 15), $returns->id, 'Inserted ID not matched');
     $this->assertEquals(array(5, 5), $newDataset->catid, 'New catid should be 5');
 }
 /**
  * Save will auto detect is conditions matched in data or not.
  * If matched, using update, otherwise we will create it as new record.
  *
  * @param mixed $dataset      The data set contains data we want to save.
  * @param array $condFields   The where condition tell us record exists or not, if not set,
  *                            will use primary key instead.
  * @param bool  $updateNulls  Update empty fields or not.
  *
  * @return  mixed|DataSet Saved data set.
  */
 public function save($dataset, $condFields = null, $updateNulls = false)
 {
     $this->observers->update('onBeforeSave', array(&$dataset, &$condFields, &$updateNulls));
     $dataset = parent::save($dataset, $condFields, $updateNulls);
     $this->observers->update('onAfterSave', array(&$dataset));
     return $dataset;
 }