Commit 8e752b86 authored by Patrick Barroca's avatar Patrick Barroca 🐧

fix volatile findAllBy with multiple negations

parent facf291b
Pipeline #7428 passed with stage
in 20 seconds
......@@ -80,7 +80,7 @@ class Storm_Model_PersistenceStrategy_Volatile extends Storm_Model_PersistenceS
if (!empty($negations))
$values = array_values(array_filter($values,
function($instance) use($negations) {
return !$this->containsAllAttributes($instance, $negations);
return $this->containsNoneAttributes($instance, $negations);
}));
$values = $this->ordered($values, $order);
......@@ -161,17 +161,32 @@ class Storm_Model_PersistenceStrategy_Volatile extends Storm_Model_PersistenceS
return array_slice($result, (int)$parts[0], (int)$parts[1]);
}
public function containsAllAttributes($model, $select) {
foreach ($select as $key => $value) {
if (!array_key_exists($key, $model)
|| ($model[$key]!=$value
&& !(is_array($value) && in_array($model[$key], $value))))
foreach ($select as $key => $value)
if (!$this->containsAttribute($model, $key, $value))
return false;
}
return true;
}
public function containsNoneAttributes($model, $select) {
foreach ($select as $key => $value)
if ($this->containsAttribute($model, $key, $value))
return false;
return true;
}
public function containsAttribute($model, $key, $value) {
return array_key_exists($key, $model)
&& ($model[$key] == $value
|| (is_array($value) && in_array($model[$key], $value)));
}
public function find($id) {
if (!isset($this->_instances[$id]))
return null;
......
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