Skip to content
Snippets Groups Projects
Commit 253f43f3 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #53376 number of unique through field

parent 57fb2c7f
1 merge request!19hotline #53376 number of unique through field
......@@ -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
*
......
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