Skip to content

Added support for ObjectIds in fields other than _id & improved date casting #1523

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
wants to merge 12 commits into from

Conversation

Flambe
Copy link

@Flambe Flambe commented May 18, 2018

I've extended the $casts property so that it's now possible to specify fields as 'objectid'. If you specify a field as 'objectid', it will be converted to one when you save/search for something.

Example syntax:

class User extends .../Model {
    protected $casts = [
        'book_id' => 'objectid'
    ];
}

This PR also fixes issues with the $dates array not being followed when using dot notation.

This should solve #356 as you can now specify relationships in the $casts array. I decided not to make it the default behaviour for relationships as Mongo does not enforce relationship types, and as to not break backwards compatibility.

(other related issues: #134 #449 #350)

@Flambe Flambe changed the title Added support for ObjectIds in fields other than _id Added support for ObjectIds in fields other than _id & improved date casting Jun 11, 2018
@keanass
Copy link

keanass commented Jun 25, 2018

why Some checks were not successful ? please we need this feature asap can you check it +1

@Djuki
Copy link

Djuki commented Sep 26, 2018

@jenssegers @Flambe What are the obstacles for this PR to be merged? Is there something we can do to help testing or additional work?

@Flambe
Copy link
Author

Flambe commented Sep 26, 2018

@jenssegers @Flambe What are the obstacles for this PR to be merged? Is there something we can do to help testing or additional work?

@Djuki I'm pretty sure there are a few edge cases with the casting that I've missed. If you find any, I'll try and get them fixed, or you could make a PR on the repo for this PR. Otherwise I'm not sure what needs to be done.

@bytewoopy
Copy link

Did anyone manage to solve this?

@Flambe
Copy link
Author

Flambe commented Jul 15, 2019

@bytewoopy We're still using this branch for our own usage of the library. We haven't been putting in an active effort to keep it ready to merge as we've had no feedback from the maintainers.

Besides a few edge cases with casting, it's working as intended.

@Smolevich
Copy link
Contributor

@Flambe do you want merge this PR into stable release?

@Flambe
Copy link
Author

Flambe commented Dec 19, 2019

@Smolevich I'd still like to get it merged, though it needs updating first and I haven't got around to that yet.

@Smolevich
Copy link
Contributor

@Smolevich I'd still like to get it merged, though it needs updating first and I haven't got around to that yet.

Ok, ping if you resolve conflicts

@Flambe
Copy link
Author

Flambe commented Dec 19, 2019

Will do, though it will likely be after the new year

@divine
Copy link
Contributor

divine commented Jan 19, 2020

@Flambe laravel 7 has merged custom cast types ( see laravel/framework#31035 ), will it help without modifying much of code?

@Smolevich what do you think?

Thank you!

@Smolevich
Copy link
Contributor

Looks like as it can help, but needs to investigate

@Flambe
Copy link
Author

Flambe commented Jan 19, 2020

I completely forgot about the conflicts, I'll try and get them done soon if I have some time!

As Smolevich said, it'll need investigation if that'll help. Using that would also restrict us to Laravel 7 I believe.

@divine
Copy link
Contributor

divine commented Jan 20, 2020

I completely forgot about the conflicts, I'll try and get them done soon if I have some time!

I myself will be waiting for this too so fingers crossed 🙏 .

Thank you for your contribution!

This was referenced Jan 20, 2020
@jansgescheit
Copy link

A improvement idea, use a const instead of someId => 'objectid' someId => self::CAST_OBJECTID

@@ -480,4 +686,39 @@ public function __call($method, $parameters)

return parent::__call($method, $parameters);
}

/**
* @inheritdoc
Copy link
Contributor

Choose a reason for hiding this comment

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

Fill params please in dock block

}

/**
* @inheritdoc
Copy link
Contributor

Choose a reason for hiding this comment

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

Add dock block for $key

@rennokki
Copy link
Contributor

That's a freaking huge PR. I think it has to wait until a further stage of the package.

@divine
Copy link
Contributor

divine commented Feb 23, 2020

Hi there,

This feature will be released within next version.

Closing for now.

Thanks.

@divine divine closed this Feb 23, 2020
@Flambe
Copy link
Author

Flambe commented Feb 25, 2020

Thank you @divine! Sorry for not getting to this sooner.

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

Successfully merging this pull request may close these issues.

9 participants