diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..909fdb44db6f264f20b310e4566d07329060ddd6 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,3 @@ +test:app: + script: + - bash build.sh \ No newline at end of file diff --git a/build.sh b/build.sh index 5afdcec6699c4f75ea57ba84c2ccbdc70853ffb7..b2dd815ad2705aaa3675d4c191408f70a05346d5 100644 --- a/build.sh +++ b/build.sh @@ -1,9 +1,6 @@ #!/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 diff --git a/src/Storm/Model/Abstract.php b/src/Storm/Model/Abstract.php index 0411b20e18e36968f3d8ee7a08d7e2f43774aeb0..39136c57122f875842e122a6708bb1e4db99a458 100644 --- a/src/Storm/Model/Abstract.php +++ b/src/Storm/Model/Abstract.php @@ -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 *