浏览代码

Documentation on #5

Artur Welp 6 年之前
父节点
当前提交
ac24b8cc30
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      src/ORM/Entity.php

+ 12 - 4
src/ORM/Entity.php

@@ -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();
         }