Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix different format of $results in afterFind #4223

Merged
merged 2 commits into from
Sep 3, 2014

Conversation

chinpei215
Copy link
Contributor

Fixes #2529 and #4221

Now, we can get consistent format of $resutls in afterFind.
And we can keep backward compatibility if Model::$useConsistentAfterFind is set to false.
Then, we will get $results without a model key in some cases.

It occurs when a model and the children models are related to a same model.
For example, such as the following:

* User hasMany Comment
* User hasMany Article
* Article hasMany Comment
Refs cakephp#2529

As of this commit, we can get consistent format of $resutls in afterFind.
And we can keep backward compatibility if Model::$useConsistentAfterFind is set to false.
@markstory markstory added this to the 2.5.4 milestone Aug 11, 2014
@@ -1375,10 +1399,15 @@ public function queryAssociation(Model $Model, Model $LinkModel, $type, $associa
$this->_mergeAssociation($row, $merge, $association, $type);
}
} else {
if (!$prefetched && $LinkModel->useConsistentAfterFind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this property can be set to false for the old behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't need this property.
I think that the old behavior is a bug.

@chinpei215
Copy link
Contributor Author

I had to explain what was changed in detail.

Deep hasOne / belongsTo association
Before:

array(
    'id' => '1',
    'name' => 'foo',
)

After:

array(
    0 => array(
        'ModelName' => array(
            'id' => '1',
            'name' => 'foo',
        )
    )
)

Limited hasMany association
Before:

array(
    0 => array(
        'id' => '1',
        'name' => 'foo',
    ),
    1 => array(
        'id' => '2',
        'name' => 'bar',
    )
)

After:

// afterFind() is called for each record.
// This is the same behavior as unlimited hasMany.
array(
    0 => array(
        'ModelName' => array(
            'id' => '1',
            'name' => 'foo',
        )
    )
)
array(
    0 => array(
        'ModelName' => array(
            'id' => '2',
            'name' => 'bar',
        )
    )
)

And previously, Model::find() parameter 'callbacks' is ignored in these cases.
Now, afterFind() is not called any more when 'callbacks' is false or 'before'.

@markstory markstory modified the milestones: 2.5.4, 2.6.0 Aug 11, 2014
@markstory
Copy link
Member

Any objections to merging this?

@chinpei215
Copy link
Contributor Author

@markstory Would it better to remeve 'useConsistentAfterFind' ?

lorenzo added a commit that referenced this pull request Sep 3, 2014
Fix different format of $results in afterFind
@lorenzo lorenzo merged commit b5bfbfc into cakephp:2.6 Sep 3, 2014
@markstory
Copy link
Member

@chinpei215 No I think it xould be useful for people that don't want to get the new behaviour.

@chinpei215 chinpei215 deleted the 2.6-issue2529-fix branch February 3, 2017 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants