load() public method

The default implementation simply stores the data returned by BaseActiveFixture::getData in [[data]]. You should usually override this method by putting the data into the underlying database.
public load ( )
コード例 #1
0
ファイル: ActiveFixture.php プロジェクト: sciurodont/yii2
 /**
  * Loads the fixture data.
  * Data will be batch inserted into the given collection.
  */
 public function load()
 {
     parent::load();
     $data = $this->getData();
     $this->getCollection()->batchInsert($data);
     foreach ($data as $alias => $row) {
         $this->data[$alias] = $row;
     }
 }
コード例 #2
0
 /**
  * Loads the fixture.
  *
  * It will then populate the table with the data returned by [[getData()]].
  *
  * If you override this method, you should consider calling the parent implementation
  * so that the data returned by [[getData()]] can be populated into the table.
  */
 public function load()
 {
     parent::load();
     $table = $this->getTableSchema();
     foreach ($this->getData() as $alias => $row) {
         $this->db->createCommand()->insert($table->fullName, $row)->execute();
         if ($table->sequenceName !== null) {
             foreach ($table->primaryKey as $pk) {
                 if (!isset($row[$pk])) {
                     $row[$pk] = $this->db->getLastInsertID($table->sequenceName);
                     break;
                 }
             }
         }
         $this->data[$alias] = $row;
     }
 }