Skip to content
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

Implements take method() #754

Merged
merged 1 commit into from
Apr 22, 2021
Merged

Implements take method() #754

merged 1 commit into from
Apr 22, 2021

Conversation

stephandesouza
Copy link
Contributor

@stephandesouza stephandesouza commented Mar 26, 2021

The current limit implementation introduced at #621 does it on the wrong manner, and totally different as expected from orderBy method().

To prevent BC I implemented Eloquent's limit as take (take is an alias to limit) and adjusted the limit description.

This PR also fixes #726 and #426

@stephandesouza
Copy link
Contributor Author

@bsormagec can you help with this?

We're using since suggested here and no problems found with both methods.

@bsormagec bsormagec merged commit 2bd5680 into andersao:master Apr 22, 2021

return $this->parserResult($results);
return $this->all($columns);
Copy link

@juliomotol juliomotol May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Breaking change, in one of our project we were doing $repository->limit(10)->get().

After updating to 2.7.6, it now throws Too few arguments to function Illuminate\Support\Collection::get(), 0 passed in /home/deploy/www/vivamusicgroup/app/Http/Composers/Backend/DashboardComposer.php on line 85 and at least 1 expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgrading to 2.7.5 what object is returned when using $repository->limit(10)?

I don't get how parserResult() is returning a different object there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgrading to 2.7.5 what object is returned when using $repository->limit(10)

It returns a Illuminate/Database/Eloquent/Builder.

I don't get how parserResult() is returning a different object there.

I'm not quite sure either, I haven't used and Presenters in my projects yet...

public function parserResult($result)
{
if ($this->presenter instanceof PresenterInterface) {
if ($result instanceof Collection || $result instanceof LengthAwarePaginator) {
$result->each(function ($model) {
if ($model instanceof Presentable) {
$model->setPresenter($this->presenter);
}
return $model;
});
} elseif ($result instanceof Presentable) {
$result = $result->setPresenter($this->presenter);
}
if (!$this->skipPresenter) {
return $this->presenter->present($result);
}
}
return $result;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i see... without presenters parseResult parses nothing, and only return the builder. The old limit method causes this mislead.

I don’t know how can this be fixed, for me this is a bug on parseResult. @bsormagec can you help us?

@juliomotol Is easy for you adapt to use ‘all’ where ‘get’ is used with limit?

$repository->limit(10)->all()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breaking change was that the query was concluded when the all() method was called.

Prior to this commit, we still needed to chain the all()/get() after limit().

We've already updated all the repositories to no longer chain all()/get() after limit().

These comments are just to notify you that this is a breaking change in our case when we upgraded to the latest version.

@andersao @bsormagec

@stephandesouza stephandesouza deleted the fixes-limit branch May 28, 2021 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limiting results with presenter switched on
3 participants