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

Using Model::hydrate()->first() throws error #607

Closed
stemis opened this issue Jun 22, 2020 · 0 comments · Fixed by #609
Closed

Using Model::hydrate()->first() throws error #607

stemis opened this issue Jun 22, 2020 · 0 comments · Fixed by #609
Assignees
Labels
bug Something isn't working

Comments

@stemis
Copy link

stemis commented Jun 22, 2020

  • Larastan Version: 0.6.0
  • --level used: 1

Description

With the introduction of #538 , the Eloquent's hydrate() function cannot be chained with ->first() anymore.

I can name multiple reasons why one would use hydrate(), such as:

  1. Using eloquent models from the result of a stored procedure.
  2. Unserialize json models back to eloquent from for example a logging database.
  3. Using data from $object->getRawOriginal() in order to utilize model casts

Laravel code where the issue was found

User::hydrate(['user_id' => 123, 'name' => 'John Doe'])->first();
$storedProcedureRows = $this->callStoredProcedure();
User::hydrate($storedProcedureRows)->first();

Error:

Called 'first' on Laravel collection, but could have been retrieved as a query. 
@stemis stemis changed the title Using Model::hydrate()->first() throws error Using Model::hydrate()->first() throws error Jun 22, 2020
@Daanra Daanra self-assigned this Jun 22, 2020
@szepeviktor szepeviktor added the bug Something isn't working label Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants