Skip to content

[4.0.0] Relation exists query fails always #2064

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
hylke94 opened this issue Jul 16, 2020 · 11 comments
Closed

[4.0.0] Relation exists query fails always #2064

hylke94 opened this issue Jul 16, 2020 · 11 comments

Comments

@hylke94
Copy link

hylke94 commented Jul 16, 2020

  • 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..

@Christophvh
Copy link

The maintainers have removed relationships in version 4

@Xeroxi91
Copy link

Xeroxi91 commented Aug 4, 2020

Hi @hylke94
we have developed a package that provides a better support for MongoDB relationships embedsOne and embedsMany in Laravel 7 Projects.
You can find it here https://github.com/offline-agency/laravel-mongo-auto-sync
I hope it will be useful. Let me know 😉

@divine
Copy link
Contributor

divine commented Aug 7, 2020

The maintainers have removed relationships in version 4

@Christophvh embedded relationships eloquent magic has been removed only. This is a bit different completely.

--

@hylke94 we have tests for that type of relationship.

Have you checked that?

Minimal reproduction repo might help as well.

@hylke94
Copy link
Author

hylke94 commented Aug 18, 2020

@divine No, i do not run the tests from third party packages..
Also, a minimal reproduction repo looked a bit overkill. It is a basic Eloquent function which every model got...

May I suggest to at least throw an exception for relation function that are not (going to) working anymore? I already did not use the Mongo relations for their bad support, but this one worked fine in previous versions. So, to be honest, if this default Eloquent function is not going to work anymore with Laravel 7, please overwrite the function to throw an exception.

@divine
Copy link
Contributor

divine commented Sep 14, 2020

We have postponed version 4 release while at the same there will be new release for L7 support.

Thanks!

Closing as it's being resolved.

@divine divine closed this as completed Sep 14, 2020
@hylke94
Copy link
Author

hylke94 commented Sep 14, 2020

We have postponed version 4 release while at the same there will be new release for L7 support.

Thanks!

Closing as it's being resolved.

When will you release if I may ask?
Also, L8 is out already..

I don't see any update in code here... How is it all of a sudden resolved then? What has changed or is fixed? Can we test this somehow? Maybe with a new alpha release?

@divine
Copy link
Contributor

divine commented Sep 14, 2020

@hylke94 please check master, take a look at this PR
#2097

Later today we will release a new version for L7 3.7. Regarding L8 it's also ready, PR will be pushed today night.

Thanks.

@hylke94
Copy link
Author

hylke94 commented Sep 17, 2020

@hylke94 please check master, take a look at this PR
#2097

Later today we will release a new version for L7 3.7. Regarding L8 it's also ready, PR will be pushed today night.

Thanks.

It could be me, but I don't see the new releases...

To confirm.. We should go back a version (from 4.0-alpha to 3.7) to get our Laravel 7 support now? And for the Laravel 8 support, we need which version?

@divine
Copy link
Contributor

divine commented Sep 17, 2020

@hylke94 please check master, take a look at this PR
#2097
Later today we will release a new version for L7 3.7. Regarding L8 it's also ready, PR will be pushed today night.
Thanks.

It could be me, but I don't see the new releases...

To confirm.. We should go back a version (from 4.0-alpha to 3.7) to get our Laravel 7 support now? And for the Laravel 8 support, we need which version?

Correct. For L7 - 3.7 and L8 - 3.8. Version 4 will be postponed for L9 probably but no plans for now.

Draft release is ready and will be released shortly.

Thanks!

@hylke94
Copy link
Author

hylke94 commented Sep 29, 2020

@divine two weeks later... And still waiting for a Laravel 8 release...

@divine
Copy link
Contributor

divine commented Sep 29, 2020

@divine two weeks later... And still waiting for a Laravel 8 release...

@hylke94 I'm really sorry but we don't have enough permissions to merge this PR #2108 (comment)

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants