Skip to content

Commit

Permalink
Merge branch 'release/1.1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Mar 9, 2017
2 parents 4b43a8d + 03aa12e commit a64210f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ engines:
- 80ef7f404dd4f054ca51d9ee12d9e9dd # we exit from toStrign() because it can't throw exceptions
- ae61f5e0cda0328c140f3b7298dbb8af # don't complain about call to static connection, as it's a fallback
- e71149b967391adfaf3347a53d3c0023 # don't complain about $junk used in foreach when we only need keys
- 26d65d6b7bfd58eba544a4669b552401 # Model::save can be longer than 100 lines
checks:
CyclomaticComplexity: # because we solve complex stuff
enabled: false
Expand All @@ -27,6 +26,8 @@ engines:
enabled: false
Design/TooManyMethods: # because we solve complex stuff
enabled: false
Design/LongMethod: # because methods are as long as we need them to be
enabled: false
ExcessivePublicCount: # because Model has too many public methods
enabled: false
Design/TooManyFields: # because we solve complex things
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.10

Aggregate fields (hasMany->addField) will now coalesce results
to automatically display 0 even if no related record exist.

## 1.1.9

Added Field::getCaption()
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
],
"require": {
"php": ">=5.5.0",
"atk4/dsql": "~1.0.9",
"atk4/core": "~1.1.4"
"atk4/dsql": "~1.1.1",
"atk4/core": "~1.1.11"
},
"require-dev": {
"phpunit/phpunit": "4.*",
Expand Down
12 changes: 10 additions & 2 deletions src/Persistence_SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ public function action($m, $type, $args = [])
return $q;

case 'fx':
case 'fx0':
if (!isset($args[0], $args[1])) {
throw new Exception([
'fx action needs 2 arguments, eg: ["sum", "amount"]',
Expand All @@ -572,10 +573,17 @@ public function action($m, $type, $args = [])
$field = is_string($args[1]) ? $m->getElement($args[1]) : $args[1];
$this->initQueryConditions($m, $q);
$m->hook('initSelectQuery', [$q, $type]);

if ($type == 'fx') {
$expr = "$fx([])";
} else {
$expr = "coalesce($fx([]), 0)";
}

if (isset($args['alias'])) {
$q->reset('field')->field($q->expr("$fx([])", [$field]), $args['alias']);
$q->reset('field')->field($q->expr($expr, [$field]), $args['alias']);
} else {
$q->reset('field')->field($q->expr("$fx([])", [$field]));
$q->reset('field')->field($q->expr($expr, [$field]));
}

return $q;
Expand Down
2 changes: 1 addition & 1 deletion src/Reference_Many.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function addField($n, $defaults = [])
$field = isset($defaults['field']) ? $defaults['field'] : $n;

$e = $this->owner->addExpression($n, function () use ($defaults, $field) {
return $this->refLink()->action('fx', [$defaults['aggregate'], $field]);
return $this->refLink()->action('fx0', [$defaults['aggregate'], $field]);
});

if (isset($defaults['type'])) {
Expand Down

0 comments on commit a64210f

Please sign in to comment.