mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 13:58:55 +08:00
Fixes #17089: Fixed caching of related records when via() using with callable
This commit is contained in:
committed by
Alexander Makarov
parent
6aa6359bbc
commit
2da6773b68
@ -6,7 +6,7 @@ Yii Framework 2 Change Log
|
||||
|
||||
- Bug #17094: Fixed response on 204 status. Now it is empty (GHopperMSK)
|
||||
- Bug #17098: Fixed message/extract when using message params returned from method calls (rugabarbo)
|
||||
|
||||
- Bug #17089: Fixed caching of related records when `via()` using with callable (rugabarbo)
|
||||
|
||||
2.0.16 January 30, 2019
|
||||
-----------------------
|
||||
|
||||
@ -170,16 +170,20 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||
} elseif (is_array($this->via)) {
|
||||
// via relation
|
||||
/* @var $viaQuery ActiveQuery */
|
||||
list($viaName, $viaQuery) = $this->via;
|
||||
list($viaName, $viaQuery, $viaCallableUsed) = $this->via;
|
||||
if ($viaQuery->multiple) {
|
||||
if ($this->primaryModel->isRelationPopulated($viaName)) {
|
||||
if ($viaCallableUsed) {
|
||||
$viaModels = $viaQuery->all();
|
||||
} elseif ($this->primaryModel->isRelationPopulated($viaName)) {
|
||||
$viaModels = $this->primaryModel->$viaName;
|
||||
} else {
|
||||
$viaModels = $viaQuery->all();
|
||||
$this->primaryModel->populateRelation($viaName, $viaModels);
|
||||
}
|
||||
} else {
|
||||
if ($this->primaryModel->isRelationPopulated($viaName)) {
|
||||
if ($viaCallableUsed) {
|
||||
$model = $viaQuery->one();
|
||||
} elseif ($this->primaryModel->isRelationPopulated($viaName)) {
|
||||
$model = $this->primaryModel->$viaName;
|
||||
} else {
|
||||
$model = $viaQuery->one();
|
||||
|
||||
@ -74,7 +74,7 @@ trait ActiveRelationTrait
|
||||
if (is_object($this->via)) {
|
||||
$this->via = clone $this->via;
|
||||
} elseif (is_array($this->via)) {
|
||||
$this->via = [$this->via[0], clone $this->via[1]];
|
||||
$this->via = [$this->via[0], clone $this->via[1], $this->via[2]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,8 @@ trait ActiveRelationTrait
|
||||
public function via($relationName, callable $callable = null)
|
||||
{
|
||||
$relation = $this->primaryModel->getRelation($relationName);
|
||||
$this->via = [$relationName, $relation];
|
||||
$callableUsed = $callable !== null;
|
||||
$this->via = [$relationName, $relation, $callableUsed];
|
||||
if ($callable !== null) {
|
||||
call_user_func($callable, $relation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user