Skip to content

getConstrainedRelatedId method not returning ids as string if key is a numeric string #2182

Open
@danielsouzaaf

Description

@danielsouzaaf
  • Laravel-mongodb Version: 3.6.6
  • PHP Version: 7.3.18
  • Database Driver & Version: mongodb/mongodb 1.6.1

Description:

When using a whereHas filter, if the field under the whereHas clause is a string with a numeric value, getConstrainedRelatedIds on the QueriesRelationships trait is returning the keys as numeric instead of string. With that, if the column in the where clause is a string, it fails.

Steps to reproduce

  1. Create a parent register with a _id PK as string and another field for testing purposes, e.g: active: true.
  2. Create two child associated with the parent register
  3. Created Example:
Parent: {
      _id: "12345",
      "active": true
},

Child: {
   _id:"id1",
  "parent_id": "12345"
},
Child: {
  _id: "id2,
  "parent_id": "12345"
}
  1. Run the query:
Child::whereHas('parent', function ($query) {
       return $query->where('active', true);
       })

Expected behaviour

It should return the two childs

Actual behaviour

None child is returned.

Logs: Insert log.txt here (if necessary)

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