bosnadev / repository

Laravel Repositories is a package for Laravel 5 which is used to abstract the database layer. This makes applications much easier to maintain.
https://bosnadev.com
825 stars 235 forks source link

findWhere after Criteria #67

Open carlituxman opened 8 years ago

carlituxman commented 8 years ago

I'm doing a criteria before a query like:

$all = $this->repo->findWhere(['status_id'=> $status->id, 'user_id'=> 1])->count();

my criteria is like this:

public function apply($model, Repository $repository) { $users = User::filtered()->lists('id')->toArray(); $model = $model->where('user_id', $users); return $model; }

the result of criteria is correct, but when I do the findWhere after it returns 0 (and should be return more)

carlituxman commented 8 years ago

the problem is because I have a loop after the criteria, only do it well in the first iteration

I'm researching what's happen...

the problem is because (I think) the criteria apply in every loop again

carlituxman commented 8 years ago

The problem is because in every iteration the query is stacked I solve using: $this->repo->skipCriteria(); $this->repo->pushCriteria(new myCriteria());

in every iteration

carlituxman commented 8 years ago

this should be cleared in every find, findWhere, ... ??