LaraParse icon indicating copy to clipboard operation
LaraParse copied to clipboard

Using injected repository twice returns incorrect results

Open nicklee1990 opened this issue 9 years ago • 3 comments

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

  1. Adding a resetQuery method to be called first for each repository method
  2. 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?

nicklee1990 avatar Jul 03 '15 10:07 nicklee1990

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?

iamraffe avatar Nov 04 '15 03:11 iamraffe

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?

ghost avatar Nov 04 '15 10:11 ghost

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.

iamraffe avatar Nov 04 '15 11:11 iamraffe