-
Notifications
You must be signed in to change notification settings - Fork 118
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
does not work with hybridrelations between mysql and mongodb relationships #30
Comments
Skimming over the other library it looks like the issue may be in the What version of Laravel are you using? Do you get the same error running the following without the filters?
|
I think you're on the right track! I'm using Laravel 5.4. And yes I do get the same error running the code you supplied
|
It looks like they should override the |
well.. upon doing a little more digging on the very popular package https://github.com/jenssegers/laravel-mongodb/issues?utf8=%E2%9C%93&q=wherehas It looks like having the "wherehas" working properly for hybrid relations has been a repeatedly requested feature going all the way back to 2014.. and the owner himself has said that implementing this seems very difficult.. and people continue to ask for it.. myself included. I think unfortunately it must not be easy to make it work at all.. or in any case no one seems to know how to do it. If you think you have an idea of how to make it work and wanted to give it a try at adding a PR there.. I think that would make you a real hero ;) |
I threw together a rough patch for it. You wanna give it a test spin before I submit the pr? https://github.com/Tucker-Eric/laravel-mongodb/commit/266305caeed70cf8ee787bcd0140c9fca2f0bcd6 |
absolutely! will test it today and let you know if I run into any troubles. wow thanks for taking this on!! I will support your PR as I'm sure others will.. it's been a long time coming! Does using this branch also automagically makes your EloquentFilter work on mysql->mongo hybrid relations? |
Yup! Although I haven't tested the 2 together, there isn't anything that should break it in this branch. This will also work mongo->mysql relationships too. It just won't support |
Alright alright! I pulled in your branch and am glad I did because I found a problem. On the one hand, this query which used to fail now works!
So that's a win! Awesome! On the other hand, this query which worked before, now fails!
Where User and Match are mysql models and Profile is a mongodb model So it seems that your fix has corrected the mysql->whereHas(mongodb)->with(mongodb) but is now interfering with the scenario mysql->whereHas(mysql)->with(mongodb) this is my user model in case it's helpful
Let me know if you need me to provide more info |
Ok, it should be good. I added some tests for hybrid |
Seems to work beautifully!! Tried the eloquent filter as well
That works perfectly too! And re-tried the two scenarios that I mentioned above and they now both work as expected! That's some really fantastic work you've done here! Thank you so much! I'll be using your branch for now. I hope @jenssegers approves your PR quickly! I know many of us have been waiting for has() and whereHas() to be added to his library for a long time so you're going to make a lot of happy people with this! You rock :) |
I'm going to close this for now. We can reopen if there are issues with that pr. |
I know this is probably outside the scope of your project but I think it would be really cool if I could get it to work.
I'm using https://github.com/jenssegers/laravel-mongodb which supports hybrid relations between mysql and mongodb models.
I am able to do this no problem User::with('profile')->all();
Where User is a mysql model and Profile is a mongodb model
Furthermore your Filterable trait works out of the box on the mongodb model which is great and I am having a lot of enjoyment using it!
so $users = User::filter($request->get()) and $profiles = Profile::filter($request->get()) both work great.
But if I try to do $users = User::filter(['gender' => 'male'])->get(); then I get errors and the errors are basically showing that it is looking for the profile fields inside mysql instead of making those queries on the mongodb collection.
I've set up my models properly
My User model uses a UserFilter which has
And my ProfileFilter has
And I've confirmed that the gender function above DOES get called. But when it does I get this error
Basically it's ignoring my HybridRelations setup and assuming that Profile is another mysql model.
The fact that your EloquentFilter DOES work on my mongodb model when used without a relation tells me that this can probably be made to work without too much difficulty.
Is there any chance you could add this functionality or put me in the right direction?
I have a feeling part of the answer might lie in https://github.com/jenssegers/laravel-mongodb/blob/master/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
Many thanks!
The text was updated successfully, but these errors were encountered: