lithium\data\source\mongo_db\Exporter::toCommand PHP Method

toCommand() public static method

public static toCommand ( $changes )
    public static function toCommand($changes)
    {
        $result = array();
        foreach (static::$_commands as $from => $to) {
            if (!isset($changes[$from])) {
                continue;
            }
            if (!$to) {
                $result = array_merge($result, $changes[$from]);
            }
            $result[$to] = $changes[$from];
        }
        unset($result['$set']['_id']);
        return $result;
    }

Usage Example

 /**
  * Tests that arrays of nested objects can be appended to and will be updated using the proper
  * MongoDB operators.
  */
 public function testAppendingNestedObjectArray()
 {
     $model = $this->_model;
     $model::schema(false);
     $model::schema(array('accounts' => array('type' => 'object', 'array' => true), 'accounts.name' => array('type' => 'string')));
     $doc = new Document(compact('model'));
     $this->assertEqual(array(), $doc->accounts->data());
     $doc->sync();
     $data = array('name' => 'New account');
     $doc->accounts[] = new Document(compact('data'));
     $result = Exporter::get('update', $doc->export());
     $expected = array('update' => array('accounts.0' => $data));
     $this->assertEqual($expected, $result);
     $result = Exporter::toCommand($result);
     $expected = array('$set' => array('accounts.0' => $data));
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\data\source\mongo_db\Exporter::toCommand