-
Notifications
You must be signed in to change notification settings - Fork 881
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
Conversation
@bsormagec can you help with this? We're using since suggested here and no problems found with both methods. |
|
||
return $this->parserResult($results); | ||
return $this->all($columns); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
l5-repository/src/Prettus/Repository/Eloquent/BaseRepository.php
Lines 1074 to 1095 in ad55bf2
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; | |
} |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
The current
limit
implementation introduced at #621 does it on the wrong manner, and totally different as expected fromorderBy
method().To prevent BC I implemented Eloquent's
limit
astake
(take
is an alias tolimit
) and adjusted thelimit
description.This PR also fixes #726 and #426