yiisoft / yiisoft/active-record
Faulty caching in AR relations with via and callable
Open
@cebe is already working on this.
Since Jul 5, 2016.
type:bug
- Dominant language
- PHP
- Stars
- 119
- Forks
- 38
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 1
Description
The following code yields an unexpected behavior:
public function getCity()
{
return $this->hasOne(Cities::className(), ['id' => 'city_id'])
->via('orderPts',function($q){
$q->andWhere(['order_pts.idx' => 1]);
})
}
The problem is due to callable in via. If I use $model->city the result of the city relation is cached together with the additional condition from the callable. Then all requests to $model->orderPts return the result cached by $model->city with additional condition.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.