yiisoft / yiisoft/active-record
AR refresh() with relations
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 119
- Forks
- 38
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 1
Description
What steps will reproduce the problem?
$video = Video::find()->andWhere(['id' => $videoId])
->with(['videoType', 'videoThumbnails'])
->one();
// DATA IS GOOD
$videoArray = $video->toArray([], ['videoType', 'videoThumbnails']);
// do some video manipulations
// now refresh video object
$video->refresh();
// NO RELATIONS!
$videoArray = $video->toArray([], ['videoType', 'videoThumbnails']);
//WORKAROUND
$video->videoType;
$video->vdeoThumbnails;
// DATA IS GOOD NOW
$videoArray = $video->toArray([], ['videoType', 'videoThumbnails']);
What is the expected result?
repopulate existing/fetched relations
What do you get instead?
nothing
Additional info
| ---------------- | ---
| Yii version | 2.0.13
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.
Research direction
Reproduce the provided Yii Active Record example, including with(['videoType', 'videoThumbnails']), refresh(), and the final toArray() call. Trace the refresh() entry point and relation-loading behavior, then verify that the fetched relations are populated again and appear in the serialized result after refresh().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100