set() public méthode

For example: $doc->set(array('title' => 'Lorem Ipsum', 'value' => 42));
public set ( array $data, array $options = [] ) : void
$data array An associative array of fields and values to assign to the `Document`.
$options array
Résultat void
Exemple #1
0
 public function testBooleanValues()
 {
     $doc = new Document(array('model' => $this->_model));
     $doc->tall = false;
     $doc->fat = true;
     $doc->set(array('hair' => true, 'fast' => false));
     $expected = array('tall', 'fat', 'hair', 'fast');
     $this->assertEqual($expected, array_keys($doc->data()));
 }
Exemple #2
0
 /**
  * Saves model data to the database.
  *
  * @return  array
  */
 public function save()
 {
     $this->saveRelationships();
     $this->appendRelationshipData();
     $type = $this->exists() ? 'update' : 'create';
     $doc = new Document();
     $doc->set($this->to_a());
     $query = new Query(array('entity' => $doc, 'model' => get_class($this), 'conditions' => array($this->primaryKey => $this->{$this->primaryKey})));
     $db = static::connection();
     $result = $db->{$type}($query);
     $exported = $doc->export();
     $this->exists(true);
     $this->data[$this->primaryKey] = $exported['update'][$this->primaryKey];
     return $result;
 }
 public function testFieldRemoval()
 {
     $doc = new Document(array('exists' => true, 'data' => array('numbers' => new DocumentSet(array('data' => array(7, 8, 9))), 'deeply' => new Document(array('pathKey' => 'deeply', 'exists' => true, 'data' => array('nested' => 'object'))), 'foo' => 'bar')));
     unset($doc->numbers);
     $result = Exporter::get('update', $doc->export());
     $this->assertEqual(array('numbers' => true), $result['remove']);
     $doc->set(array('flagged' => true, 'foo' => 'baz', 'bar' => 'dib'));
     unset($doc->foo, $doc->flagged, $doc->numbers, $doc->deeply->nested);
     $result = Exporter::get('update', $doc->export());
     $expected = array('foo' => true, 'deeply.nested' => true, 'numbers' => true);
     $this->assertEqual($expected, $result['remove']);
     $this->assertEqual(array('bar' => 'dib'), $result['update']);
 }