Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHPORM-229 Make Query\Builder return objects instead of array to match Laravel behavior #3107

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

Merged
GromNaN merged 1 commit into mongodb:5.0 from GromNaN:PHPORM-229
Aug 27, 2024

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 21, 2024
edited
Loading

Fix PHPORM-229

Laravel Query Builder always returns objects (source).

This is a major breaking change that requires changing all array access into property access. Returning a MongoDB\Model\BSONDocument and MongoDB\Model\BSONArray is not possible as the data is casted with native PHP cast feature in Laravel code: (object) $result and (array) $result.

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@GromNaN GromNaN added this to the 5.0 milestone Aug 21, 2024
@GromNaN GromNaN requested review from a team as code owners August 21, 2024 13:37
@GromNaN GromNaN changed the title (削除) PHPORM-229 Make Query\Builder return objects instead of array to matc... (削除ここまで) (追記) PHPORM-229 Make Query\Builder return objects instead of array to match Laravel's behavior (追記ここまで) Aug 21, 2024

// Fix for legacy support, converts the results to arrays instead of objects.
$options['typeMap'] = ['root' => 'array', 'document' => 'array'];
$options['typeMap'] = ['root' => 'object', 'document' => 'array'];
Copy link
Member Author

Choose a reason for hiding this comment

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

Shall we update the type of document to object also, to get the same type for root and embedded documents?

Copy link
Member

Choose a reason for hiding this comment

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

If the root document is returned as an object, it would make sense to return all embedded documents as objects as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, butLaravel have sort of embedded document with "JSON" fields. They are returned as array...

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. In that case, let's leave it as-is for consistency with Laravel, even though it seems strange in general.

@GromNaN GromNaN changed the title (削除) PHPORM-229 Make Query\Builder return objects instead of array to match Laravel's behavior (削除ここまで) (追記) PHPORM-229 Make Query\Builder return objects instead of array to match Laravel behavior (追記ここまで) Aug 22, 2024
Copy link
Contributor

Is it possible that all v5 pr be merge this week? I just have an expectation that v5 will be release this week. But if not, no pressure just want those big changes to be merge so we can evaluate if we need to add rdbms or just this package can do fine itself.

GromNaN reacted with thumbs up emoji

Copy link
Member

alcaeus commented Aug 26, 2024

data is casted with native PHP cast feature in Laravel code: (object) $result and (array) $result.

Note that we could leverage the cast_object object handler in extension classes to facilitate converting a PackedArray into an array.

Copy link
Member Author

GromNaN commented Aug 26, 2024

data is casted with native PHP cast feature in Laravel code: (object) $result and (array) $result.

Note that we could leverage the cast_object object handler in extension classes to facilitate converting a PackedArray into an array.

Tracking in PHPC-2426

@GromNaN GromNaN requested a review from alcaeus August 26, 2024 10:05
@GromNaN GromNaN force-pushed the PHPORM-229 branch 3 times, most recently from 83a7f8e to fa2c542 Compare August 26, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alcaeus alcaeus alcaeus approved these changes

+1 more reviewer

@rustagir rustagir rustagir approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.0

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /