You are here

public function DBObject::save in Entity Construction Kit (ECK) 7.2

Same name and namespace in other branches
  1. 7.3 eck.classes.inc \DBObject::save()

Save.

2 calls to DBObject::save()
Bundle::save in ./eck.classes.inc
Save the entity type.
EntityType::save in ./eck.classes.inc
Save.
2 methods override DBObject::save()
Bundle::save in ./eck.classes.inc
Save the entity type.
EntityType::save in ./eck.classes.inc
Save.

File

./eck.classes.inc, line 94
Classes for all the different objects used in ECK.

Class

DBObject
@file Classes for all the different objects used in ECK.

Code

public function save() {

  // Before we save, lets serialize the properties that require it.
  foreach ($this->serialize as $property) {
    $this->{$property} = drupal_json_encode($this->{$property});
  }
  if ($this->isNew) {
    $this->id = db_insert($this->table)
      ->fields($this->data)
      ->execute();
  }
  else {

    // Well I need to know what the primary id is to set up the condition.
    $primary_key = $this->primaryKeys[0];
    db_update($this->table)
      ->condition($primary_key, $this->{$primary_key}, '=')
      ->fields($this->data)
      ->execute();
  }

  // Now that we are done saving lets deserialize in case that for some
  // reason we will continue manipulating the properties.
  foreach ($this->serialize as $property) {
    $this->{$property} = drupal_json_decode($this->{$property});
  }
  $this->isNew = FALSE;
}