- 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.
This commit is contained in:
Dave Mc Nicoll 2020-12-04 13:21:59 -05:00
parent f74d1907d9
commit 9e84bd3536
3 changed files with 30 additions and 14 deletions

View File

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

View File

@ -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) ) {

View File

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