Documentation on #5

This commit is contained in:
Artur Welp
2019-04-25 04:14:04 -03:00
parent 7b48b20443
commit ac24b8cc30
+12 -4
View File
@@ -97,26 +97,33 @@ abstract class Entity {
}
private function create() {
//First, let's verify id polices
//Manual and empty don't need special treatments
if (!empty(static::_idPolice) && static::_idPolice['type'] != 'manual') {
//Get the actual max value of the key
$maxVal = DBInstance::queryOne("SELECT max(id) as id FROM {" . static::tableName . "}");
$maxVal = ($maxVal) ? $maxVal : 0;
if (isset(static::_idPolice['min']) && static::_idPolice['min'] > $maxVal->id) {
// If the next val is smaller than the minumum value
if (isset(static::_idPolice['min']) && static::_idPolice['min'] > $maxVal->id+1) {
// The id value shpuld assume the min value
$this->id = static::_idPolice['min'];
} else {
// The id is bigger than the min or min is not set
if (isset(static::_idPolice['step'])) {
//If sted is defined, increment by step multiples
$this->id = $maxVal->id + static::_idPolice['step'];
} else {
$this->id = $maxVal->id + 1;
}
}
//If the id is bigger than the max value. There is problems
if (isset(static::_idPolice['max']) && $maxVal->id > static::_idPolice['max']) {
//Do not store the register
return false;
}
}
var_dump($this);
$columns = array_diff(array_keys(get_object_vars($this)), static::_ignore);
$obj = (array) $this;
@@ -137,6 +144,7 @@ abstract class Entity {
$sql = "INSERT INTO {" . static::tableName . "} ($first_argument) VALUES ($second_argument)";
DBInstance::execute($sql, $insert_data, static::connectionName);
// If there is a id pollice applied, do not get the inserted id
if ( empty(static::_idPolice) ){
$this->id = DBInstance::lastInsert();
}