hipsterjazzbo / LaraParse

LaraParse provides a nice integration for using Parse (parse.com) with Laravel 5+
MIT License
27 stars 19 forks source link

Using injected repository twice returns incorrect results #30

Open nicklee1990 opened 9 years ago

nicklee1990 commented 9 years ago

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?

iamraffe commented 9 years ago

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?

ghost commented 9 years ago

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?

iamraffe commented 9 years ago

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.