Skip to content

[4.0.0] Relation exists query fails always #2064

Closed
@hylke94

Description

@hylke94
  • Laravel-mongodb Version: 4.0.0-alpha.1
  • PHP Version: 7.4.0
  • Database Driver & Version: mongodb-1.7.4

Description:

The exists function on a relation always fails with a query run in MongoDB.

For MySQL, Laravel performs an exists function on the database and returns this results with an 'exists' alias. For the same query in mongodb (the exists query compile function is overwritten by this package), it applies the filters (for the foreign key), adds a limit of 1 record and returns that.
The exists query isn't overwritten in de mongo base model of this package, so it is handled by the Laravel base model en checks for the exists column. This column doesn't exists, so it falls back to returning false (see Illuminate\Database\Query\Builder::exists()).

Steps to reproduce

  1. Create a link between two mongo models, or a hybrid relation from mysql to mongodb.
  2. Check for existence on the mongo relation.

Expected behaviour

Telling me if there are records found.

Actual behaviour

It falls back to always telling no.

Logs:

MySQL exists query:

select exists(select * from `[MYSQL]` inner join `[MONGODB]` on `[MYSQL]`.`id` = `[MONGODB]`.`[MYSQL]_id` where `[MONGODB]`.`[MYSQL]_id` = ? and `[MYSQL]`.`deleted_at` is null) as `exists`

MongoDB exists query:

[MONGODB].find({"$and":[{"[MONGODB]_id":1371},{"[MONGODB]_id":{"$ne":null}}]},{"limit":1,"typeMap":{"root":"array","document":"array"}})

Also the mongodb queries doesn't support parameter binding? I see now the ID is put in the query immediately..

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