public function DBObject::save in Entity Construction Kit (ECK) 7.3
Same name and namespace in other branches
- 7.2 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 103 - 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->is_new) {
$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];
// Do not update Primary Key field.
$data = $this->data;
unset($data[$primary_key]);
db_update($this->table)
->condition($primary_key, $this->{$primary_key}, '=')
->fields($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->is_new = FALSE;
}