- Fixed some mssql caused bugs within Insert and Create into querybuilding

- Added some methods to EntityCollection
This commit is contained in:
Dave M. 2020-12-07 17:26:51 +00:00
parent f74d1907d9
commit 65de1dd849
2 changed files with 95 additions and 79 deletions

View File

@ -180,18 +180,18 @@ class EntityCollection extends \ArrayObject {
switch (true) { switch (true) {
case is_null($value): case is_null($value):
$list[] = $item->$keyColumn; $list[] = $item->$keyColumn;
break; break;
case is_callable($value): case is_callable($value):
$list[$item->$keyColumn] = $value($item); $list[$item->$keyColumn] = $value($item);
break; break;
case is_object($value): case is_object($value):
case is_string($value): case is_string($value):
$value = (string) $value; $value = (string) $value;
$list[$item->$keyColumn] = $item->$value; $list[$item->$keyColumn] = $item->$value;
break; break;
} }
} }
@ -220,18 +220,34 @@ class EntityCollection extends \ArrayObject {
} }
public function fromArray(array $datasets, ? string /*stringable*/ $entityClass = null) : self public function fromArray(array $datasets, ? string /*stringable*/ $entityClass = null) : self
{
foreach($datasets as $dataset) {
$this->append( $this->arrayToEntity($dataset, $entityClass) );
}
return $this;
}
public function arrayToEntity(array $dataset, ? string /*stringable*/ $entityClass = null) : object
{ {
if ( ! ($this->entityClass || $entityClass) ) { if ( ! ($this->entityClass || $entityClass) ) {
throw new \Exception("An entity class name must be provided to be instanciated and populated before insertion into this collection."); throw new \Exception("An entity class name must be provided to be instanciated and populated before insertion into this collection.");
} }
$className = $entityClass ?: $this->entityClass; $className = $this->entityClass;
foreach($datasets as $dataset) { return ( new $className() )->fromArray($dataset);
$this->append( (new $className() )->fromArray($dataset) ); }
public function append($value) : void
{
if ( is_array($value) ) {
$this->append( $this->arrayToEntity($value) );
}
else {
parent::append($value);
} }
return $this;
} }
public function mergeWith( /*array|EntityCollection*/ $datasets ) : self public function mergeWith( /*array|EntityCollection*/ $datasets ) : self

View File

@ -64,11 +64,11 @@ class QueryBuilder
{ {
if ( null === $this->getFragment(Query\Insert::class) ) { if ( null === $this->getFragment(Query\Insert::class) ) {
if ( $schema ) { if ( $schema ) {
$table = "\"$schema\".$table"; $table = "$schema.$table";
} }
if ( $database ) { if ( $database ) {
$table = "\"$database\".$table"; $table = "$database.$table";
} }
$insert = new Query\Insert(); $insert = new Query\Insert();
@ -327,11 +327,11 @@ class QueryBuilder
{ {
if ( null === $this->getFragment(Query\Create::class) ) { if ( null === $this->getFragment(Query\Create::class) ) {
if ( $schema ) { if ( $schema ) {
$table = "\"$schema\".$table"; $table = "$schema.$table";
} }
if ( $database ) { if ( $database ) {
$table = "\"$database\".$table"; $table = "$database.$table";
} }
$create = new Query\Create(); $create = new Query\Create();