You are here

public function FeedsDataHandler::insert in Feeds 6

Inserts a multi dimensional record.

Parameters

$record: An array of a record to store. Keys are the names of fields or names of joining tables. Names of joining tables must start with #. Joined table keys must contain an array of values to insert.

Example: This is an array that inserts a title and a description into the base table and a series of tags into a depending table 'feeds_data_tags'. Note how the actual serial key is missing, it will be generated and passed on to depending tables by insert().

array( 'title' => 'Example title', 'description' => 'Lorem ipsum...', '#feeds_data_tags' => array( array( 'tid' => 12, ), array( 'tid' => 14, ), array( 'tid' => 28, ), ), );

Overrides DataHandler::insert

File

includes/FeedsDataHandler.inc, line 112
Data handler used in FeedsDataProcessor.

Class

FeedsDataHandler
Simple multidimensional data handler. Treats tables that join to this handler's table through FeedsDatahandler::key as a cluster. Records in this cluster are regarded as belonging to one multidimensional data set joined by FeedsDatahandler::key.

Code

public function insert(&$record) {
  parent::insert($record);
  foreach ($record as $key => $value) {
    if ($handler = $this
      ->joinedTableHandler($key)) {
      foreach ($value as $v) {

        // parent::insert() has populated the key or key must have been passed
        // in.
        $v[$this->key] = $record[$this->key];
        $handler
          ->insert($v);
      }
    }
  }
}