Skip to content

all ObjectId fields (including polymorphic relations must be _id or ended with ._id) #2374

Description

@farmani
  • Laravel-mongodb Version: 3.8.4
  • PHP Version: 8.1.1
  • Database Driver & Version: 4.2

Description:

Bases on this code https://github.com/jenssegers/laravel-mongodb/blob/master/src/Query/Builder.php#L939 only _id and all fields ended with ._id will cast into the ObjectId before running where queries this is not mentioned anywhere in the doc. this specifically make problems when you are going to use polymorphic relations in the models because relation would be name_id and name_type and so they won't cast into the ObjectId

naming polymophic relation to something ended with . is not a big deal but at least should mention in the doc or consider to find a better solution like looking for a defined property in the model class like ObjectIds or even better let's developer use $casts and rely on it

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions