Commit df48fbf3 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'hotline#53376_optimisation_affichage_destinataires_newsletters' into 'master'

hotline #53376 number of unique through field

See merge request !19
parents 57fb2c7f a96d16ec
Pipeline #429 passed with stage
in 4 seconds
test:app:
script:
- bash build.sh
\ No newline at end of file
#!/bin/sh
COVERAGE_DIR="coverage/$(basename "$PWD")/${CI_BUILD_REF_NAME}"
git submodule init
git submodule update
phpunit -c tests/phpunit.xml --coverage-text=coverage.txt --coverage-html="../${COVERAGE_DIR}"
echo "</pre>"
echo "<a href='/${COVERAGE_DIR}'>Code coverage</a>"
echo "<pre>"
phpunit -c tests/phpunit.xml --coverage-text=coverage.txt
cat coverage.txt
......@@ -767,19 +767,8 @@ abstract class Storm_Model_Abstract {
if (array_key_exists($field, $this->_has_many_attributes))
return count($this->_has_many_attributes[$field]);
if (isset($map['through'])) {
$through_field = $map['through'];
$dependents = $this->_get($through_field);
if (isset($this->_belongs_to[$through_field]))
$dependents = array_filter([$dependents]);
return array_sum(array_map(
function($dependent) use ($field) {
return $dependent->_numberOf($this->_getDependentFieldNameForInstance($field, $dependent));
},
$dependents));
}
if (isset($map['through']))
return $this->_numberOfThrough($field, $map);
if (isset($this->_belongs_to[$field]))
return $this->_get($field) ? 1 : 0;
......@@ -792,6 +781,25 @@ abstract class Storm_Model_Abstract {
}
protected function _numberOfThrough($field, $map) {
$through_field = $map['through'];
if (isset($map['unique']) && $map['unique'])
return $this->_numberOf($through_field);
$dependents = $this->_get($through_field);
if (isset($this->_belongs_to[$through_field]))
$dependents = array_filter([$dependents]);
return array_sum(array_map(
function($dependent) use ($field) {
return $dependent->_numberOf($this->_getDependentFieldNameForInstance($field, $dependent));
},
$dependents));
}
/**
* Update with a [name] => value formatted array
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment