-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
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.
@@ -1375,10 +1399,15 @@ public function queryAssociation(Model $Model, Model $LinkModel, $type, $associa | |||
$this->_mergeAssociation($row, $merge, $association, $type); | |||
} | |||
} else { | |||
if (!$prefetched && $LinkModel->useConsistentAfterFind) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I had to explain what was changed in detail. Deep hasOne / belongsTo association array( 'id' => '1', 'name' => 'foo', ) After: array( 0 => array( 'ModelName' => array( 'id' => '1', 'name' => 'foo', ) ) ) Limited hasMany association 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. |
Any objections to merging this? |
@markstory Would it better to remeve 'useConsistentAfterFind' ? |
Fix different format of $results in afterFind
@chinpei215 No I think it xould be useful for people that don't want to get the new behaviour. |
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.