From 9e84bd35363cea826a8c15a4bf7de83095e1b8a1 Mon Sep 17 00:00:00 2001
From: Dave Mc Nicoll <dave.mcnicoll@cslsj.qc.ca>
Date: Fri, 4 Dec 2020 13:21:59 -0500
Subject: [PATCH] - Set ID as a bigint by default now. - EntityCollection now
 transforms array received from append() into entity and then append them. -
 Corrected a big bug within QueryBuilder which was missed when it was made
 compatible with MSSQL.

---
 src/Annotation/Property/Field/Id.php |  2 +-
 src/EntityCollection.php             | 30 +++++++++++++++++++++-------
 src/QueryBuilder.php                 | 12 +++++------
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/Annotation/Property/Field/Id.php b/src/Annotation/Property/Field/Id.php
index 931b0ae..277373c 100644
--- a/src/Annotation/Property/Field/Id.php
+++ b/src/Annotation/Property/Field/Id.php
@@ -11,7 +11,7 @@ class Id extends \Ulmus\Annotation\Property\Field {
         $this->attributes['primary_key'] = true;
         $this->attributes['auto_increment'] = true;
         
-        parent::__construct('int');
+        parent::__construct('bigint');
     }
 
 }
diff --git a/src/EntityCollection.php b/src/EntityCollection.php
index 5f94cfe..aad784f 100644
--- a/src/EntityCollection.php
+++ b/src/EntityCollection.php
@@ -221,19 +221,35 @@ class EntityCollection extends \ArrayObject {
         
     public function fromArray(array $datasets, ? string /*stringable*/ $entityClass = null) : self 
     {
-        if ( ! ($this->entityClass || $entityClass) ) {
-            throw new \Exception("An entity class name must be provided to be instanciated and populated before insertion into this collection.");
-        }
-        
-        $className = $entityClass ?: $this->entityClass;
-        
+
         foreach($datasets as $dataset) {
-            $this->append( (new $className() )->fromArray($dataset) );
+            $this->append( $this->arrayToEntity($dataset, $entityClass) );
         }
         
         return $this;
     }
     
+    public function arrayToEntity(array $dataset, ? string /*stringable*/ $entityClass = null) : object 
+    {
+        if ( ! ($this->entityClass || $entityClass) ) {
+            throw new \Exception("An entity class name must be provided to be instanciated and populated before insertion into this collection.");
+        }
+
+        $className = $this->entityClass;
+
+        return ( new $className() )->fromArray($dataset);
+    }
+    
+    public function append($value) : void
+    {
+        if ( is_array($value) ) {
+            $this->append( $this->arrayToEntity($value) );
+        }
+        else {
+            parent::append($value);
+        }
+    }
+    
     public function mergeWith( /*array|EntityCollection*/ $datasets ) : self
     {
         if ( is_object($datasets) ) {
diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php
index 5ce92a9..2d0bb8e 100644
--- a/src/QueryBuilder.php
+++ b/src/QueryBuilder.php
@@ -64,11 +64,11 @@ class QueryBuilder
     {
         if ( null === $this->getFragment(Query\Insert::class) ) {    
             if ( $schema ) {
-                $table = "\"$schema\".$table";
+                $table = "$schema.$table";
             }
-
+            
             if ( $database ) {
-                $table = "\"$database\".$table";
+                $table = "$database.$table";
             }
             
             $insert = new Query\Insert();
@@ -327,11 +327,11 @@ class QueryBuilder
     {
         if ( null === $this->getFragment(Query\Create::class) ) {
             if ( $schema ) {
-                $table = "\"$schema\".$table";
+                $table = "$schema.$table";
             }
-
+            
             if ( $database ) {
-                $table = "\"$database\".$table";
+                $table = "$database.$table";
             }
 
             $create = new Query\Create();