Skip to content
Permalink
Browse files

Fix count errors in ORM.

Fix the various count() errors in the ORM package.

I had to rework how join conditions were generated as count() on
a generic ExpressionInterface object fails in PHP7.2. Instead we can
convert expressions into strings and then generate the appropriate SQL.
I also found the link between count() and having a sql() method was
pretty loose, where as the new checks are more correct.
  • Loading branch information...
markstory committed Aug 7, 2017
1 parent 37ca8a6 commit 969cbe16e173140acb8da6f787d587a83c4761d5
Showing with 11 additions and 5 deletions.
  1. +7 −2 src/Database/QueryCompiler.php
  2. +2 −2 src/ORM/Association.php
  3. +2 −1 src/ORM/Marshaller.php
@@ -235,8 +235,13 @@ protected function _buildJoinPart($parts, $query, $generator)
}
$joins .= sprintf(' %s JOIN %s %s', $join['type'], $join['table'], $join['alias']);
if (isset($join['conditions']) && count($join['conditions'])) {
$joins .= sprintf(' ON %s', $join['conditions']->sql($generator));
$condition = '';
if (isset($join['conditions']) && $join['conditions'] instanceof ExpressionInterface) {
$condition = $join['conditions']->sql($generator);
}
if (strlen($condition)) {
$joins .= " ON {$condition}";
} else {
$joins .= ' ON 1 = 1';
}
@@ -419,10 +419,10 @@ public function getTarget()
throw new RuntimeException(sprintf(
$errorMessage,
get_class($this->_sourceTable),
$this->_sourceTable ? get_class($this->_sourceTable) : 'null',
$this->getName(),
$this->type(),
get_class($this->_targetTable),
$this->_targetTable ? get_class($this->_targetTable) : 'null',
$className
));
}
@@ -463,7 +463,8 @@ protected function _loadAssociatedByIds($assoc, $ids)
$primaryKey = array_map([$target, 'aliasField'], $primaryKey);
if ($multi) {
if (count(current($ids)) !== count($primaryKey)) {
$first = current($ids);
if (!is_array($first) || count($first) !== count($primaryKey)) {
return [];
}
$filter = new TupleComparison($primaryKey, $ids, [], 'IN');

0 comments on commit 969cbe1

Please sign in to comment.
You can’t perform that action at this time.