LaraParse
LaraParse copied to clipboard
Using injected repository twice returns incorrect results
If in a method I do:
$parseObject = $this->someRepo->find($id);
$collection = $this->someRepo->all();
The $collection will only contain a single result which matches the ID of the $parseObject. I believe this is because we set a query on the repo in the constructor, but then reuse this same query. We should really be resetting the query for each call which could be done by
- Adding a resetQuery method to be called first for each repository method
- Removing the current AbstractRepo constructor and setting the query as part of each repository method
Effectively those 2 options are the same thing, just a style difference really. Any other ideas on a fix?
Oh man just spent countless hours figuring out what was wrong with my code.
Having passed so much time since your post, what do you think is the best practice to deal with this?
I honestly can't remember but it's something which needs to be fixed for sure. i'll have a look at fixing it this week if I have time. If I remember correctly, I think moving the all() request before the find() worked for me but not sure?
It happened to my while using findAllBy(), which was dependant of the find(). So swapping was not possible.
For now I'm restarting at first on each repo method. If there's a better way, suggestions are appreciated.