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

Fix nested dates format #2271

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

Closed
alexsmko wants to merge 1 commit into mongodb:4.1 from alexsmko:fix-nested-date-format
Closed

Conversation

@alexsmko
Copy link

@alexsmko alexsmko commented Jun 9, 2021
edited
Loading

Copy link
Contributor

divine commented Jun 12, 2021

Hello,

This looks like a breaking change for the projects depending on the old behavior, however, on the other hand, this is definitely a fix.

@Smolevich what do you think?

Thanks!

}

// Convert dot-notation dates.
foreach ($this->getDates() as $key) {
Copy link

@shaedrich shaedrich Jul 14, 2021
edited
Loading

Choose a reason for hiding this comment

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

Your change works for EmbedsOne but not for EmbedsMany since Arr::has()/Arr::set() doesn't support dot-syntax on nested arrays (entry.*.date). Interestingly, array_get()/array_set() do. So I'd add this to make it work for both EmbedsOne and EmbedsMany:

Suggested change
foreach ($this->getDates() as $key) {
foreach ($this->getDates() as $key) {
$res = data_get($attributes, $key);
if (is_array($res)) {
$res = array_filter($res);
}
if (Str::contains($key, '.') && Arr::has($attributes, $key)) {
Arr::set($attributes, $key, $this->serializeDate(
$this->asDateTime(Arr::get($attributes, $key))
));
} else if (Str::contains($key, '.') && !empty($res)) {
data_set($attributes, $key, $this->serializeDate(
$this->asDateTime(Arr::get($attributes, $key))
));
}
}

Copy link

@shaedrich shaedrich Sep 3, 2024

Choose a reason for hiding this comment

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

@GromNaN Does #3105 support the dot syntax?

Copy link
Member

@GromNaN GromNaN Sep 3, 2024

Choose a reason for hiding this comment

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

In fact, the query builder will convert any DateTimeInterface into UTCDatetime, and inversely for results. Regardless of the path, no need to specify any date casting. That the benefit of having a native date type in MongoDB vs SQL database that store strings for dates.

shaedrich reacted with thumbs up emoji
Copy link

@shaedrich shaedrich Sep 3, 2024

Choose a reason for hiding this comment

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

Awesome 👍🏻 Thanks for the clarification

@GromNaN GromNaN added this to the 5.0 milestone Jul 22, 2024
Copy link
Member

GromNaN commented Sep 3, 2024

Fixed by #3105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@GromNaN GromNaN GromNaN left review comments

+1 more reviewer

@shaedrich shaedrich shaedrich left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

5.0

Development

Successfully merging this pull request may close these issues.

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