yiisoft / yiisoft/active-record

Faulty caching in AR relations with via and callable

Open
#48 6 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.