public function save()
{
global $wpdb;
// Get the model's properties
$props = $this->properties();
// Flatten complex objects
$props = $this->flatten_props($props);
// Insert or update?
if (is_null($props[static::get_primary_key()])) {
$wpdb->insert($this->get_table(), $props);
$this->{static::get_primary_key()} = $wpdb->insert_id;
} else {
$wpdb->update(static::get_table(), $props, array(static::get_primary_key() => $this->{static::get_primary_key()}));
}
return $this->id;
}