From d8bd31ad84eb15221f16cfe398ab4c54e6c5198f Mon Sep 17 00:00:00 2001 From: Jorge Castro Date: Tue, 16 Feb 2021 10:24:17 -0300 Subject: [PATCH] * 2.9 2021-02-16 see README.md --- README.md | 7 +- composer.json | 2 +- .../generated/AbstractTableCategoryRepo.php | 71 +++++++++---- .../generated/AbstractTableChildRepo.php | 73 ++++++++----- .../generated/AbstractTableGrandChildRepo.php | 69 ++++++++---- .../AbstractTableGrandChildTagRepo.php | 71 +++++++++---- .../generated/AbstractTableParentExtRepo.php | 69 ++++++++---- .../generated/AbstractTableParentRepo.php | 100 ++++++++---------- .../AbstractTableParentxCategoryRepo.php | 76 ++++++++----- .../repomysql/generated/TableCategoryRepo.php | 2 +- .../repomysql/generated/TableChildRepo.php | 2 +- .../generated/TableGrandChildRepo.php | 2 +- .../generated/TableGrandChildTagRepo.php | 2 +- .../generated/TableParentExtRepo.php | 2 +- .../repomysql/generated/TableParentRepo.php | 2 +- .../generated/TableParentxCategoryRepo.php | 2 +- .../AbstractTableCategoryModel.php | 34 +++++- .../AbstractTableChildModel.php | 34 +++++- .../AbstractTableGrandChildModel.php | 34 +++++- .../AbstractTableGrandChildTagModel.php | 34 +++++- .../AbstractTableParentExtModel.php | 34 +++++- .../AbstractTableParentModel.php | 43 ++++++-- .../AbstractTableParentxCategoryModel.php | 34 +++++- .../generatedmodel/TableCategoryModel.php | 2 +- .../generatedmodel/TableChildModel.php | 2 +- .../generatedmodel/TableGrandChildModel.php | 2 +- .../TableGrandChildTagModel.php | 2 +- .../generatedmodel/TableParentExtModel.php | 2 +- .../generatedmodel/TableParentModel.php | 2 +- .../TableParentxCategoryModel.php | 2 +- examples/repomysql/test_select.php | 2 +- lib/PdoOne.php | 5 +- lib/_BasePdoOneRepo.php | 7 +- lib/ext/PdoOne_Mysql.php | 2 +- 34 files changed, 592 insertions(+), 237 deletions(-) diff --git a/README.md b/README.md index cd76fed..cd2c254 100644 --- a/README.md +++ b/README.md @@ -1946,9 +1946,12 @@ In a nutshell: * Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix) - +* 2.9 2021-02-16 + * BasePdoOneRepo::getPdoOne() validates if the static class uses the right version. It is only done once + (when it creates the instance of pdoOne), so it must not affects the performance. + * **You should re-generate all ORM classes generated (if you are generated one)** * **2.8** 2021-02-13 - * Updated _BasePdoOneRepo to 4.13 + * Updated _BasePdoOneRepo to 4.13. **You should re-generate all ORM classes generated (if you are generated one)** * 2.7.1 2021-01-21 * Oracle is still a WIP (OCI) * **2.7** 2021-01-10 diff --git a/composer.json b/composer.json index d3019ed..c827a66 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "eftec/pdoone", "description": "Procedural PDO Data access class in a single Class", - "version": "2.8", + "version": "2.9", "type": "library", "keywords": [ "dao", diff --git a/examples/repomysql/generated/AbstractTableCategoryRepo.php b/examples/repomysql/generated/AbstractTableCategoryRepo.php index 78e7aae..61b393d 100644 --- a/examples/repomysql/generated/AbstractTableCategoryRepo.php +++ b/examples/repomysql/generated/AbstractTableCategoryRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableCategoryRepo @@ -27,11 +27,13 @@ abstract class AbstractTableCategoryRepo extends TestDb { const TABLE = 'TableCategory'; + const COMPILEDVERSION=3; + const IDENTITY = NULL; const PK = [ 'IdTableCategoryPK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableCategoryRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] * - * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -92,11 +95,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['IdTableCategoryPK']=isset($row['IdTableCategoryPK']) ? (int)$row['IdTableCategoryPK'] : null; !isset($row['Name']) and $row['Name']=null; // varchar @@ -152,12 +158,12 @@ public static function getDefNoInsert() { */ public static function getDefNoUpdate() { return [ - + 'IdTableCategoryPK' ]; } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -172,7 +178,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableCategoryRepo::TABLE);
         return TableCategoryRepo::class;
     }
 
@@ -219,7 +225,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableCategoryModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -227,15 +233,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableCategoryRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableCategoryRepo::getRelations($recursive); @@ -253,10 +268,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableCategoryModel::fromArray(self::_first($pk)); } @@ -343,14 +358,16 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'IdTableCategoryPK'=>0, '_TableParentxCategory'=>(in_array($recursivePrefix.'_TableParentxCategory',$recursive,true)) @@ -358,21 +375,29 @@ public static function factory($recursivePrefix='') { : null, /* ONETOMANY! */ 'Name'=>'' ]; - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'IdTableCategoryPK'=>null, '_TableParentxCategory'=>null, /* ONETOMANY! */ 'Name'=>null ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableChildRepo.php b/examples/repomysql/generated/AbstractTableChildRepo.php index 7df18c2..540b3f2 100644 --- a/examples/repomysql/generated/AbstractTableChildRepo.php +++ b/examples/repomysql/generated/AbstractTableChildRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableChildRepo @@ -27,11 +27,13 @@ abstract class AbstractTableChildRepo extends TestDb { const TABLE = 'TableChild'; + const COMPILEDVERSION=3; + const IDENTITY = 'idtablachildPK'; const PK = [ 'idtablachildPK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableChildRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] *
- * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -101,11 +104,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['idtablachildPK']=isset($row['idtablachildPK']) ? (int)$row['idtablachildPK'] : null; !isset($row['NameChild']) and $row['NameChild']=null; // varchar $row['idgrandchildFK']=isset($row['idgrandchildFK']) ? (int)$row['idgrandchildFK'] : null; @@ -172,7 +178,7 @@ public static function getDefNoUpdate() { } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -187,7 +193,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableChildRepo::TABLE);
         return TableChildRepo::class;
     }
 
@@ -217,7 +223,7 @@ public static function getDefFK($structure=false) {
 		        'key' => 'ONETOMANY',
 		        'col' => 'idtablachildPK',
 		        'reftable' => 'TableParent',
-		        'refcol' => '_idchildFK'
+		        'refcol' => '_idchild2FK'
 		    ]
 		];
     }
@@ -251,7 +257,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableChildModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -259,15 +265,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableChildRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableChildRepo::getRelations($recursive); @@ -285,10 +300,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableChildModel::fromArray(self::_first($pk)); } @@ -375,14 +390,16 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'idtablachildPK'=>0, '_TableParent'=>(in_array($recursivePrefix.'_TableParent',$recursive,true)) @@ -391,28 +408,36 @@ public static function factory($recursivePrefix='') { 'NameChild'=>'', 'idgrandchildFK'=>0, '_idgrandchildFK'=>(in_array($recursivePrefix.'_idgrandchildFK',$recursive,true)) - ? TableGrandChildRepo::factory($recursivePrefix.'_idgrandchildFK') + ? TableGrandChildRepo::factory(null,$recursivePrefix.'_idgrandchildFK') : null, /* MANYTOONE!! */ ]; isset($row['_idgrandchildFK']) and $row['_idgrandchildFK']['idgrandchildPK']=&$row['idgrandchildFK']; // linked MANYTOONE - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'idtablachildPK'=>null, '_TableParent'=>null, /* ONETOMANY! */ 'NameChild'=>null, 'idgrandchildFK'=>null, '_idgrandchildFK'=>null, /* MANYTOONE!! */ ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableGrandChildRepo.php b/examples/repomysql/generated/AbstractTableGrandChildRepo.php index f65a89f..69a2cd6 100644 --- a/examples/repomysql/generated/AbstractTableGrandChildRepo.php +++ b/examples/repomysql/generated/AbstractTableGrandChildRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableGrandChildRepo @@ -27,11 +27,13 @@ abstract class AbstractTableGrandChildRepo extends TestDb { const TABLE = 'TableGrandChild'; + const COMPILEDVERSION=3; + const IDENTITY = 'idgrandchildPK'; const PK = [ 'idgrandchildPK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableGrandChildRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] *
- * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -92,11 +95,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['idgrandchildPK']=isset($row['idgrandchildPK']) ? (int)$row['idgrandchildPK'] : null; !isset($row['NameGrandChild']) and $row['NameGrandChild']=null; // varchar @@ -157,7 +163,7 @@ public static function getDefNoUpdate() { } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -172,7 +178,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableGrandChildRepo::TABLE);
         return TableGrandChildRepo::class;
     }
 
@@ -226,7 +232,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableGrandChildModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -234,15 +240,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableGrandChildRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableGrandChildRepo::getRelations($recursive); @@ -260,10 +275,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableGrandChildModel::fromArray(self::_first($pk)); } @@ -350,14 +365,16 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'idgrandchildPK'=>0, '_TableChild'=>(in_array($recursivePrefix.'_TableChild',$recursive,true)) @@ -368,22 +385,30 @@ public static function factory($recursivePrefix='') { : null, /* ONETOMANY! */ 'NameGrandChild'=>'' ]; - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'idgrandchildPK'=>null, '_TableChild'=>null, /* ONETOMANY! */ '_TableGrandChildTag'=>null, /* ONETOMANY! */ 'NameGrandChild'=>null ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableGrandChildTagRepo.php b/examples/repomysql/generated/AbstractTableGrandChildTagRepo.php index f77acbb..dcfb48b 100644 --- a/examples/repomysql/generated/AbstractTableGrandChildTagRepo.php +++ b/examples/repomysql/generated/AbstractTableGrandChildTagRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableGrandChildTagRepo @@ -27,11 +27,13 @@ abstract class AbstractTableGrandChildTagRepo extends TestDb { const TABLE = 'TableGrandChildTag'; + const COMPILEDVERSION=3; + const IDENTITY = 'IdTablaGrandChildTagPK'; const PK = [ 'IdTablaGrandChildTagPK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableGrandChildTagRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] *
- * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -101,11 +104,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['IdTablaGrandChildTagPK']=isset($row['IdTablaGrandChildTagPK']) ? (int)$row['IdTablaGrandChildTagPK'] : null; !isset($row['Name']) and $row['Name']=null; // varchar $row['IdgrandchildFK']=isset($row['IdgrandchildFK']) ? (int)$row['IdgrandchildFK'] : null; @@ -172,7 +178,7 @@ public static function getDefNoUpdate() { } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -187,7 +193,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableGrandChildTagRepo::TABLE);
         return TableGrandChildTagRepo::class;
     }
 
@@ -242,7 +248,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableGrandChildTagModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -250,15 +256,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableGrandChildTagRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableGrandChildTagRepo::getRelations($recursive); @@ -276,10 +291,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableGrandChildTagModel::fromArray(self::_first($pk)); } @@ -366,40 +381,50 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'IdTablaGrandChildTagPK'=>0, 'Name'=>'', 'IdgrandchildFK'=>0, '_IdgrandchildFK'=>(in_array($recursivePrefix.'_IdgrandchildFK',$recursive,true)) - ? TableGrandChildRepo::factory($recursivePrefix.'_IdgrandchildFK') + ? TableGrandChildRepo::factory(null,$recursivePrefix.'_IdgrandchildFK') : null, /* MANYTOONE!! */ ]; isset($row['_IdgrandchildFK']) and $row['_IdgrandchildFK']['idgrandchildPK']=&$row['IdgrandchildFK']; // linked MANYTOONE - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'IdTablaGrandChildTagPK'=>null, 'Name'=>null, 'IdgrandchildFK'=>null, '_IdgrandchildFK'=>null, /* MANYTOONE!! */ ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableParentExtRepo.php b/examples/repomysql/generated/AbstractTableParentExtRepo.php index 753e231..e3e3025 100644 --- a/examples/repomysql/generated/AbstractTableParentExtRepo.php +++ b/examples/repomysql/generated/AbstractTableParentExtRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableParentExtRepo @@ -27,11 +27,13 @@ abstract class AbstractTableParentExtRepo extends TestDb { const TABLE = 'TableParentExt'; + const COMPILEDVERSION=3; + const IDENTITY = 'idtablaparentExtPK'; const PK = [ 'idtablaparentExtPK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableParentExtRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] *
- * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -92,11 +95,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['idtablaparentExtPK']=isset($row['idtablaparentExtPK']) ? (int)$row['idtablaparentExtPK'] : null; !isset($row['fieldExt']) and $row['fieldExt']=null; // varchar @@ -157,7 +163,7 @@ public static function getDefNoUpdate() { } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -172,7 +178,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableParentExtRepo::TABLE);
         return TableParentExtRepo::class;
     }
 
@@ -226,7 +232,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableParentExtModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -234,15 +240,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableParentExtRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableParentExtRepo::getRelations($recursive); @@ -260,10 +275,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableParentExtModel::fromArray(self::_first($pk)); } @@ -350,32 +365,42 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'idtablaparentExtPK'=>0, 'fieldExt'=>'' ]; - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'idtablaparentExtPK'=>null, 'fieldExt'=>null ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableParentRepo.php b/examples/repomysql/generated/AbstractTableParentRepo.php index 22a74a2..931fe33 100644 --- a/examples/repomysql/generated/AbstractTableParentRepo.php +++ b/examples/repomysql/generated/AbstractTableParentRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableParentRepo @@ -27,11 +27,13 @@ abstract class AbstractTableParentRepo extends TestDb { const TABLE = 'TableParent'; + const COMPILEDVERSION=3; + const IDENTITY = 'idtablaparentPK'; const PK = [ 'idtablaparentPK' ]; const ME=__CLASS__; - CONST EXTRACOLS='CURRENT_TIMESTAMP as `extracol`,20 as `extracol2`'; + const EXTRACOLS='CURRENT_TIMESTAMP as `extracol`,20 as `extracol2`'; /** * It returns the definitions of the columns
@@ -41,8 +43,9 @@ abstract class AbstractTableParentRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] *
- * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -78,7 +81,7 @@ public static function getDef($column=null,$filter=null) { 'size' => NULL, 'null' => TRUE, 'identity' => FALSE, - 'sql' => 'int' + 'sql' => 'int unsigned' ], 'fieldInt' => [ 'phptype' => 'int', @@ -90,7 +93,7 @@ public static function getDef($column=null,$filter=null) { 'sql' => 'int' ], 'fielDecimal' => [ - 'phptype' => 'decimal', + 'phptype' => 'float', 'conversion' => 'decimal', 'type' => 'decimal', 'size' => '9,2', @@ -149,11 +152,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['idtablaparentPK']=isset($row['idtablaparentPK']) ? (int)$row['idtablaparentPK'] : null; !isset($row['fieldVarchar']) and $row['fieldVarchar']=null; // varchar $row['idchildFK']=isset($row['idchildFK']) ? (int)$row['idchildFK'] : null; @@ -164,8 +170,6 @@ public static function convertOutputVal(&$row) { !isset($row['fieldKey']) and $row['fieldKey']=null; // no conversion $row['extracol']=isset($row['extracol']) ? PdoOne::dateConvert($row['extracol'], 'sql', 'human') : null; !isset($row['extracol2']) and $row['extracol2']=null; // - isset($row['_idchildFK']) - and $row['_idchildFK']['idtablachildPK']=&$row['idchildFK']; // linked MANYTOONE isset($row['_TableParentExt']) and $row['_TableParentExt']['idtablaparentExtPK']=&$row['idtablaparentPK']; // linked ONETOONE @@ -216,8 +220,8 @@ public static function getDefKey() { 'idtablaparentPK' => 'PRIMARY KEY', 'fieldUnique' => 'UNIQUE KEY', 'idchildFK' => 'KEY', - 'idchild2FK' => 'KEY', - 'fieldKey' => 'KEY' + 'fieldKey' => 'KEY', + 'idchild2FK' => 'KEY' ]; } @@ -242,7 +246,7 @@ public static function getDefNoUpdate() { } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -257,15 +261,14 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableParentRepo::TABLE);
         return TableParentRepo::class;
     }
 
     public static function getDefFK($structure=false) {
         if ($structure) {
             return [
-			    'idchild2FK' => 'FOREIGN KEY REFERENCES`TableChild`(`idtablachildPK`)',
-			    'idchildFK' => 'FOREIGN KEY REFERENCES`TableChild`(`idtablachildPK`)'
+			    'idchild2FK' => 'FOREIGN KEY REFERENCES`TableChild`(`idtablachildPK`)'
 			];
         }
         /* key,refcol,reftable,extra */
@@ -275,28 +278,14 @@ public static function getDefFK($structure=false) {
 		        'refcol' => 'idtablachildPK',
 		        'reftable' => 'TableChild',
 		        'extra' => '',
-		        'name' => 'FK_TableParent_TableChild1'
+		        'name' => 'TableParent_fk2'
 		    ],
 		    '_idchild2FK' => [
 		        'key' => 'PARENT',
 		        'refcol' => 'idtablachildPK',
 		        'reftable' => 'TableChild',
 		        'extra' => '',
-		        'name' => 'FK_TableParent_TableChild1'
-		    ],
-		    'idchildFK' => [
-		        'key' => 'FOREIGN KEY',
-		        'refcol' => 'idtablachildPK',
-		        'reftable' => 'TableChild',
-		        'extra' => '',
-		        'name' => 'FK_TableParent_TableChild'
-		    ],
-		    '_idchildFK' => [
-		        'key' => 'MANYTOONE',
-		        'refcol' => 'idtablachildPK',
-		        'reftable' => 'TableChild',
-		        'extra' => '',
-		        'name' => 'FK_TableParent_TableChild'
+		        'name' => 'TableParent_fk2'
 		    ],
 		    '_TableParentExt' => [
 		        'key' => 'ONETOONE',
@@ -327,9 +316,6 @@ public static function getDefFK($structure=false) {
      */        
     public static function getRelations($type='all') {
         $r= [
-		    'MANYTOONE' => [
-		        '_idchildFK'
-		    ],
 		    'ONETOONE' => [
 		        '_TableParentExt'
 		    ],
@@ -348,7 +334,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableParentModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -363,7 +349,7 @@ public static function toList($filter=null,$filterValue=null) {
      * self::setRecursive([]); // (default) no use recursivity.
      * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
      * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
-     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations first level 
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
      * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
      * 
* If array then it uses the values to set the recursivity.
@@ -373,7 +359,7 @@ public static function toList($filter=null,$filterValue=null) { * * @return TableParentRepo */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableParentRepo::getRelations($recursive); @@ -391,10 +377,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableParentModel::fromArray(self::_first($pk)); } @@ -481,27 +467,26 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'idtablaparentPK'=>0, '_TableParentExt'=>(in_array($recursivePrefix.'_TableParentExt',$recursive,true)) - ? TableParentExt::factory($recursivePrefix.'_TableParentExt') + ? TableParentExt::factory(null,$recursivePrefix.'_TableParentExt') : null, /* ONETOONE! */ '_TableParentxCategory'=>(in_array($recursivePrefix.'_TableParentxCategory',$recursive,true)) ? [] : null, /* MANYTOMANY! */ 'fieldVarchar'=>'', 'idchildFK'=>0, - '_idchildFK'=>(in_array($recursivePrefix.'_idchildFK',$recursive,true)) - ? TableChildRepo::factory($recursivePrefix.'_idchildFK') - : null, /* MANYTOONE!! */ 'idchild2FK'=>0, 'fieldInt'=>0, 'fielDecimal'=>0.0, @@ -509,27 +494,28 @@ public static function factory($recursivePrefix='') { 'fieldUnique'=>'', 'fieldKey'=>'' ]; - isset($row['_idchildFK']) - and $row['_idchildFK']['idtablachildPK']=&$row['idchildFK']; // linked MANYTOONE isset($row['_TableParentExt']) and $row['_TableParentExt']['idtablaparentExtPK']=&$row['idtablaparentPK']; // linked ONETOONE - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'idtablaparentPK'=>null, '_TableParentExt'=>null, /* ONETOONE! */ '_TableParentxCategory'=>null, /* MANYTOMANY! */ 'fieldVarchar'=>null, 'idchildFK'=>null, - '_idchildFK'=>null, /* MANYTOONE!! */ 'idchild2FK'=>null, 'fieldInt'=>null, 'fielDecimal'=>null, @@ -537,6 +523,10 @@ public static function factoryNull() { 'fieldUnique'=>null, 'fieldKey'=>null ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/AbstractTableParentxCategoryRepo.php b/examples/repomysql/generated/AbstractTableParentxCategoryRepo.php index 1368d8f..69a266f 100644 --- a/examples/repomysql/generated/AbstractTableParentxCategoryRepo.php +++ b/examples/repomysql/generated/AbstractTableParentxCategoryRepo.php @@ -16,7 +16,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. Use instead the Repo Class. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class AbstractTableParentxCategoryRepo @@ -27,12 +27,14 @@ abstract class AbstractTableParentxCategoryRepo extends TestDb { const TABLE = 'TableParentxCategory'; + const COMPILEDVERSION=3; + const IDENTITY = 'idtablaparentPKFK'; const PK = [ 'idtablaparentPKFK', 'idcategoryPKFK' ]; const ME=__CLASS__; - CONST EXTRACOLS=''; + const EXTRACOLS=''; /** * It returns the definitions of the columns
@@ -42,8 +44,9 @@ abstract class AbstractTableParentxCategoryRepo extends TestDb * self::getDef('sql'); // ['colName'=>'sql','colname2'=>'sql2'] * self::getDef('identity',true); // it returns the columns that are identities ['col1','col2'] * - * PHP Types: binary, date, datetime, decimal,int, string,time, timestamp
- * PHP Conversions: datetime3 (human string), datetime2 (iso), datetime (datetime class), timestamp (int), bool, int, float
+ * PHP Types: binary, date, datetime, decimal/float,int, string,time, timestamp
+ * PHP Conversions: datetime (datetime class), datetime2 (iso),datetime3 (human string) + * , datetime4 (sql no conversion!), timestamp (int), bool, int, float
* Param Types: PDO::PARAM_LOB, PDO::PARAM_STR, PDO::PARAM_INT
* * @param string|null $column =['phptype','conversion','type','size','null','identity','sql'][$i] @@ -93,11 +96,14 @@ public static function getDef($column=null,$filter=null) { /** * It converts a row returned from the database.
- * If the column is missing then it sets the null value. + * If the column is missing then it sets the field as null. * * @param array $row [ref] */ public static function convertOutputVal(&$row) { + if($row===false || $row===null) { + return; + } $row['idtablaparentPKFK']=isset($row['idtablaparentPKFK']) ? (int)$row['idtablaparentPKFK'] : null; $row['idcategoryPKFK']=isset($row['idcategoryPKFK']) ? (int)$row['idcategoryPKFK'] : null; isset($row['_idcategoryPKFK']) @@ -159,12 +165,13 @@ public static function getDefNoInsert() { */ public static function getDefNoUpdate() { return [ - 'idtablaparentPKFK' + 'idtablaparentPKFK', + 'idcategoryPKFK' ]; } /** - * It adds a where to the income query. It could be stacked with more where()
+ * It adds a where to the query pipeline. It could be stacked with many where() * Example:
*
      * self::where(['col'=>'value'])::toList();
@@ -179,7 +186,7 @@ public static function getDefNoUpdate() {
      */
     public static function where($sql, $param = PdoOne::NULL)
     {
-        self::getPdoOne()->where($sql, $param);
+        self::getPdoOne()->where($sql, $param,false,TableParentxCategoryRepo::TABLE);
         return TableParentxCategoryRepo::class;
     }
 
@@ -253,7 +260,7 @@ public static function getRelations($type='all') {
     
     }
     
-    public static function toList($filter=null,$filterValue=null) {
+    public static function toList($filter=PdoOne::NULL,$filterValue=null) {
        if(self::$useModel) {
             return TableParentxCategoryModel::fromArrayMultiple( self::_toList($filter, $filterValue));
         }
@@ -261,15 +268,24 @@ public static function toList($filter=null,$filterValue=null) {
     }
     
     /**
-     * It sets the recursivity.
+ * It sets the recursivity. By default, if we query or modify a value, it operates with the fields of the entity. + * With recursivity, we could use the recursivity of the fields, for example, loading a MANYTOONE relation
+ * Example:
+ *
+     * self::setRecursive([]); // (default) no use recursivity.
+     * self::setRecursive('*'); // recursive every MANYTOONE,ONETOONE,MANYTOONE and ONETOONE relations (first level) 
+     * self::setRecursive('MANYTOONE'); // recursive all relations of the type MANYTOONE (first level)
+     * self::setRecursive(['_relation1','_relation2']); // recursive only the relations of the first level 
+     * self::setRecursive(['_relation1','_relation1/_subrelation1']); // recursive the relations (first and second level)
+     * 
* If array then it uses the values to set the recursivity.
* If string then the values allowed are '*', 'MANYTOONE','ONETOMANY','MANYTOMANY','ONETOONE' (first level only)
+ * * @param string|array $recursive=self::factory(); * * @return TableParentxCategoryRepo - * {@inheritDoc} */ - public static function setRecursive($recursive) + public static function setRecursive($recursive=[]) { if(is_string($recursive)) { $recursive=TableParentxCategoryRepo::getRelations($recursive); @@ -287,10 +303,10 @@ public static function limit($sql) * It returns the first row of a query. * @param array|mixed|null $pk [optional] Specify the value of the primary key. * - * @return array|bool + * @return array|bool It returns false if not file is found. * @throws Exception */ - public static function first($pk = null) { + public static function first($pk = PdoOne::NULL) { if(self::$useModel) { return TableParentxCategoryModel::fromArray(self::_first($pk)); } @@ -377,44 +393,54 @@ public static function deleteById($pk,$transactional=true) { } /** - * Initialize an empty array with default values (0 for numbers, empty for string, and array|null if recursive) - * - * @param string $recursivePrefix It is the prefix of the recursivity. + * Returns an array with the default values (0 for numbers, empty for string, and array|null if recursive) + * + * @param array|null $values =self::factory() + * @param string $recursivePrefix It is the prefix of the recursivity. * * @return array */ - public static function factory($recursivePrefix='') { + public static function factory($values = null, $recursivePrefix = '') { $recursive=static::getRecursive(); + static::setRecursive(); // reset the recursivity. $row= [ 'idtablaparentPKFK'=>0, '_idtablaparentPKFK'=>(in_array($recursivePrefix.'_idtablaparentPKFK',$recursive,true)) - ? TableParentRepo::factory($recursivePrefix.'_idtablaparentPKFK') + ? TableParentRepo::factory(null,$recursivePrefix.'_idtablaparentPKFK') : null, /* ONETOONE!! */ 'idcategoryPKFK'=>0, '_idcategoryPKFK'=>(in_array($recursivePrefix.'_idcategoryPKFK',$recursive,true)) - ? TableCategoryRepo::factory($recursivePrefix.'_idcategoryPKFK') + ? TableCategoryRepo::factory(null,$recursivePrefix.'_idcategoryPKFK') : null, /* MANYTOONE!! */ ]; isset($row['_idcategoryPKFK']) and $row['_idcategoryPKFK']['IdTableCategoryPK']=&$row['idcategoryPKFK']; // linked MANYTOONE isset($row['_idtablaparentPKFK']) and $row['_idtablaparentPKFK']['idtablaparentPK']=&$row['idtablaparentPKFK']; // linked ONETOONE - + + if ($values !== null) { + $row = array_merge($row, $values); + } return $row; } /** - * Initialize an empty array with null values + * It returns an empty array with null values and no recursivity. + * @param array|null $values=self::factoryNull() * - * @return null[] + * @return array */ - public static function factoryNull() { - return [ + public static function factoryNull($values=null) { + $row= [ 'idtablaparentPKFK'=>null, '_idtablaparentPKFK'=>null, /* ONETOONE!! */ 'idcategoryPKFK'=>null, '_idcategoryPKFK'=>null, /* MANYTOONE!! */ ]; + if ($values !== null) { + $row = array_merge($row, $values); + } + return $row; } } \ No newline at end of file diff --git a/examples/repomysql/generated/TableCategoryRepo.php b/examples/repomysql/generated/TableCategoryRepo.php index 31e9bdf..4507bda 100644 --- a/examples/repomysql/generated/TableCategoryRepo.php +++ b/examples/repomysql/generated/TableCategoryRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableCategoryRepo diff --git a/examples/repomysql/generated/TableChildRepo.php b/examples/repomysql/generated/TableChildRepo.php index 802b482..1a21c50 100644 --- a/examples/repomysql/generated/TableChildRepo.php +++ b/examples/repomysql/generated/TableChildRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableChildRepo diff --git a/examples/repomysql/generated/TableGrandChildRepo.php b/examples/repomysql/generated/TableGrandChildRepo.php index fd351bb..a830b20 100644 --- a/examples/repomysql/generated/TableGrandChildRepo.php +++ b/examples/repomysql/generated/TableGrandChildRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildRepo diff --git a/examples/repomysql/generated/TableGrandChildTagRepo.php b/examples/repomysql/generated/TableGrandChildTagRepo.php index 13b2006..2516329 100644 --- a/examples/repomysql/generated/TableGrandChildTagRepo.php +++ b/examples/repomysql/generated/TableGrandChildTagRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildTagRepo diff --git a/examples/repomysql/generated/TableParentExtRepo.php b/examples/repomysql/generated/TableParentExtRepo.php index 308db83..3013e3b 100644 --- a/examples/repomysql/generated/TableParentExtRepo.php +++ b/examples/repomysql/generated/TableParentExtRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentExtRepo diff --git a/examples/repomysql/generated/TableParentRepo.php b/examples/repomysql/generated/TableParentRepo.php index c2763f5..a688bf1 100644 --- a/examples/repomysql/generated/TableParentRepo.php +++ b/examples/repomysql/generated/TableParentRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentRepo diff --git a/examples/repomysql/generated/TableParentxCategoryRepo.php b/examples/repomysql/generated/TableParentxCategoryRepo.php index 4e3de57..29828cf 100644 --- a/examples/repomysql/generated/TableParentxCategoryRepo.php +++ b/examples/repomysql/generated/TableParentxCategoryRepo.php @@ -7,7 +7,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * EDIT THIS CODE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentxCategoryRepo diff --git a/examples/repomysql/generatedmodel/AbstractTableCategoryModel.php b/examples/repomysql/generatedmodel/AbstractTableCategoryModel.php index 14848a1..0435ad4 100644 --- a/examples/repomysql/generatedmodel/AbstractTableCategoryModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableCategoryModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableCategoryModel @@ -33,6 +33,22 @@ abstract class AbstractTableCategoryModel /** @var TableParentxCategoryModel[] $_TableParentxCategory onetomany */ public $_TableParentxCategory; + + /** + * AbstractTableCategoryModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -47,9 +63,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableChildModel.php b/examples/repomysql/generatedmodel/AbstractTableChildModel.php index 611b8fa..f938f27 100644 --- a/examples/repomysql/generatedmodel/AbstractTableChildModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableChildModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableChildModel @@ -37,6 +37,22 @@ abstract class AbstractTableChildModel /** @var TableParentModel[] $_TableParent onetomany */ public $_TableParent; + + /** + * AbstractTableChildModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -57,9 +73,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableGrandChildModel.php b/examples/repomysql/generatedmodel/AbstractTableGrandChildModel.php index d96abec..03223c6 100644 --- a/examples/repomysql/generatedmodel/AbstractTableGrandChildModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableGrandChildModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildModel @@ -35,6 +35,22 @@ abstract class AbstractTableGrandChildModel /** @var TableGrandChildTagModel[] $_TableGrandChildTag onetomany */ public $_TableGrandChildTag; + + /** + * AbstractTableGrandChildModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -52,9 +68,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableGrandChildTagModel.php b/examples/repomysql/generatedmodel/AbstractTableGrandChildTagModel.php index 5e5bd56..532e10e 100644 --- a/examples/repomysql/generatedmodel/AbstractTableGrandChildTagModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableGrandChildTagModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildTagModel @@ -35,6 +35,22 @@ abstract class AbstractTableGrandChildTagModel /** @var TableGrandChildModel $_IdgrandchildFK manytoone */ public $_IdgrandchildFK; + + /** + * AbstractTableGrandChildTagModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -52,9 +68,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableParentExtModel.php b/examples/repomysql/generatedmodel/AbstractTableParentExtModel.php index fd64ef3..f40964c 100644 --- a/examples/repomysql/generatedmodel/AbstractTableParentExtModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableParentExtModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentExtModel @@ -32,6 +32,22 @@ abstract class AbstractTableParentExtModel + + /** + * AbstractTableParentExtModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -44,9 +60,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableParentModel.php b/examples/repomysql/generatedmodel/AbstractTableParentModel.php index 9844414..8fb18f7 100644 --- a/examples/repomysql/generatedmodel/AbstractTableParentModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableParentModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentModel @@ -33,7 +33,7 @@ abstract class AbstractTableParentModel public $idchildFK; /** @var int $fieldInt */ public $fieldInt; - /** @var decimal $fielDecimal */ + /** @var float $fielDecimal */ public $fielDecimal; /** @var datetime $fieldDateTime */ public $fieldDateTime; @@ -46,13 +46,27 @@ abstract class AbstractTableParentModel /** @var mixed $extracol2 extra column: 20 */ public $extracol2; - /** @var TableChildModel $_idchildFK manytoone */ - public $_idchildFK; /** @var TableParentExtModel $_TableParentExt onetoone */ public $_TableParentExt; /** @var TableParentxCategoryModel[] $_TableParentxCategory manytomany */ public $_TableParentxCategory; + + /** + * AbstractTableParentModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -69,11 +83,6 @@ public static function fromArray($array) { $obj->fieldKey=isset($array['fieldKey']) ? $array['fieldKey'] : null; $obj->extracol=isset($array['extracol']) ? $array['extracol'] : null; $obj->extracol2=isset($array['extracol2']) ? $array['extracol2'] : null; - $obj->_idchildFK=isset($array['_idchildFK']) ? - $obj->_idchildFK=TableChildModel::fromArray($array['_idchildFK']) - : null; // manytoone - ($obj->_idchildFK !== null) - and $obj->_idchildFK->idtablachildPK=&$obj->idchildFK; // linked manytoone $obj->_TableParentExt=isset($array['_TableParentExt']) ? $obj->_TableParentExt=TableParentExtModel::fromArray($array['_TableParentExt']) : null; // onetoone @@ -85,9 +94,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/AbstractTableParentxCategoryModel.php b/examples/repomysql/generatedmodel/AbstractTableParentxCategoryModel.php index 1d69f92..c21caa3 100644 --- a/examples/repomysql/generatedmodel/AbstractTableParentxCategoryModel.php +++ b/examples/repomysql/generatedmodel/AbstractTableParentxCategoryModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * DO NOT EDIT THIS CODE. THIS CODE WILL SELF GENERATE. * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentxCategoryModel @@ -35,6 +35,22 @@ abstract class AbstractTableParentxCategoryModel /** @var TableParentModel $_idtablaparentPKFK onetoone */ public $_idtablaparentPKFK; + + /** + * AbstractTableParentxCategoryModel constructor. + * + * @param array|null $array + */ + public function __construct($array=null) + { + if($array===null) { + return; + } + foreach($array as $k=>$v) { + $this->{$k}=$v; + } + } + // public static function fromArray($array) { if($array===null) { @@ -56,9 +72,23 @@ public static function fromArray($array) { return $obj; } + + /** + * It converts the current object in an array + * + * @return mixed + */ public function toArray() { - return (array) $this; + return static::objectToArray($this); } + + /** + * It converts an array of arrays into an array of objects. + * + * @param array|null $array + * + * @return array|null + */ public static function fromArrayMultiple($array) { if($array===null) { return null; diff --git a/examples/repomysql/generatedmodel/TableCategoryModel.php b/examples/repomysql/generatedmodel/TableCategoryModel.php index 6c10f6d..419625e 100644 --- a/examples/repomysql/generatedmodel/TableCategoryModel.php +++ b/examples/repomysql/generatedmodel/TableCategoryModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableCategoryModel diff --git a/examples/repomysql/generatedmodel/TableChildModel.php b/examples/repomysql/generatedmodel/TableChildModel.php index 56e8a92..fbb7bce 100644 --- a/examples/repomysql/generatedmodel/TableChildModel.php +++ b/examples/repomysql/generatedmodel/TableChildModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableChildModel diff --git a/examples/repomysql/generatedmodel/TableGrandChildModel.php b/examples/repomysql/generatedmodel/TableGrandChildModel.php index 0087520..680942a 100644 --- a/examples/repomysql/generatedmodel/TableGrandChildModel.php +++ b/examples/repomysql/generatedmodel/TableGrandChildModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildModel diff --git a/examples/repomysql/generatedmodel/TableGrandChildTagModel.php b/examples/repomysql/generatedmodel/TableGrandChildTagModel.php index 8fd6789..8d0b31b 100644 --- a/examples/repomysql/generatedmodel/TableGrandChildTagModel.php +++ b/examples/repomysql/generatedmodel/TableGrandChildTagModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableGrandChildTagModel diff --git a/examples/repomysql/generatedmodel/TableParentExtModel.php b/examples/repomysql/generatedmodel/TableParentExtModel.php index 9d80e56..3fd7f2d 100644 --- a/examples/repomysql/generatedmodel/TableParentExtModel.php +++ b/examples/repomysql/generatedmodel/TableParentExtModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentExtModel diff --git a/examples/repomysql/generatedmodel/TableParentModel.php b/examples/repomysql/generatedmodel/TableParentModel.php index db209bb..7f2e16f 100644 --- a/examples/repomysql/generatedmodel/TableParentModel.php +++ b/examples/repomysql/generatedmodel/TableParentModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentModel diff --git a/examples/repomysql/generatedmodel/TableParentxCategoryModel.php b/examples/repomysql/generatedmodel/TableParentxCategoryModel.php index 9d62485..0ad9524 100644 --- a/examples/repomysql/generatedmodel/TableParentxCategoryModel.php +++ b/examples/repomysql/generatedmodel/TableParentxCategoryModel.php @@ -15,7 +15,7 @@ use Exception; /** - * Generated by PdoOne Version 2.1 Date generated Fri, 14 Aug 2020 16:47:00 -0400. + * Generated by PdoOne Version 2.8 Date generated Tue, 16 Feb 2021 10:15:08 -0300. * YOU COULD EDIT THIS CODE * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne * Class TableParentxCategoryModel diff --git a/examples/repomysql/test_select.php b/examples/repomysql/test_select.php index 07efd7a..48b6c3e 100644 --- a/examples/repomysql/test_select.php +++ b/examples/repomysql/test_select.php @@ -10,7 +10,7 @@ TableParentRepo::setRecursive(['*'])::toList(); -die(1); + TableParentRepo::setRecursive([ '_idchildFK', diff --git a/lib/PdoOne.php b/lib/PdoOne.php index aacce97..fb5e47a 100644 --- a/lib/PdoOne.php +++ b/lib/PdoOne.php @@ -36,7 +36,7 @@ * @package eftec * @author Jorge Castro Castillo * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne - * @version 2.8 + * @version 2.9 */ class PdoOne { @@ -3072,6 +3072,7 @@ public function generateCodeClass( abstract class Abstract{classname} extends {baseclass} { const TABLE = '{table}'; + const COMPILEDVERSION={compiled}; const IDENTITY = {identity}; const PK = {pk}; const ME=__CLASS__; @@ -3432,6 +3433,7 @@ public static function factoryNull($values=null) { '{baseclass}', '{args}', '{table}', + '{compiled}', '{namespace}', '{modelnamespace}', '{classmodellist}', @@ -3444,6 +3446,7 @@ public static function factoryNull($values=null) { $baseClass, // {baseclass} implode(",", $fa), $tableName, // {table} + _BasePdoOneRepo::BINARYVERSION, // {compiled} ($namespace) ? "namespace $namespace;" : '', //{namespace} $modelUse ? "use $modelfullClass;" : '', // {modelnamespace} $modelUse ? "$modelClass::fromArrayMultiple( self::_toList(\$filter, \$filterValue));" diff --git a/lib/_BasePdoOneRepo.php b/lib/_BasePdoOneRepo.php index 543dbfd..8f7a0dc 100644 --- a/lib/_BasePdoOneRepo.php +++ b/lib/_BasePdoOneRepo.php @@ -23,13 +23,15 @@ /** * Class _BasePdoOneRepo * - * @version 4.13 2021-02-13 + * @version 4.14 2021-02-16 * @package eftec * @author Jorge Castro Castillo * @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne */ abstract class _BasePdoOneRepo { + // it is used for compatibility. + const BINARYVERSION=3; /** @var PdoOne */ public static $pdoOne; /** @var array $gQuery =[['columns'=>[],'joins'=>[],'where'=>[]] */ @@ -109,6 +111,9 @@ protected static function getPdoOne() if (self::$pdoOne !== null) { return self::$pdoOne; } + if(self::BINARYVERSION!==static::COMPILEDVERSION) { + throw new RuntimeException(self::class.' requires a new version'); + } if (function_exists('PdoOne')) { return PdoOne(); } diff --git a/lib/ext/PdoOne_Mysql.php b/lib/ext/PdoOne_Mysql.php index 429babe..a4c1d6e 100644 --- a/lib/ext/PdoOne_Mysql.php +++ b/lib/ext/PdoOne_Mysql.php @@ -43,7 +43,7 @@ public function construct($charset) PdoOne::$dateFormat = 'Y-m-d'; PdoOne::$dateTimeFormat = 'Y-m-d H:i:s'; PdoOne::$dateTimeMicroFormat = 'Y-m-d H:i:s.u'; - PdoOne::$dateFo = 'Y-m-d'; + PdoOne::$isoDateInput = 'Y-m-d'; PdoOne::$isoDateInputTime = 'Y-m-d H:i:s'; PdoOne::$isoDateInputTimeMs = 'Y-m-d H:i:s.u'; $this->parent->isOpen = false;