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

Missing id column in default favorites table migration #27

Open
belamov opened this issue Apr 19, 2021 · 4 comments
Open

Missing id column in default favorites table migration #27

belamov opened this issue Apr 19, 2021 · 4 comments

Comments

@belamov
Copy link

belamov commented Apr 19, 2021

Missing column id in default favorites table migration

when i try to add some model to favorites it generates following query, which requires id column

SQL: insert into "favorites" ("user_id", "favoriteable_id", "favoriteable_type", "updated_at", "created_at") values (1, 2, App\Models\Institution\Institution, 2021-04-19 06:19:59, 2021-04-19 06:19:59) returning "id"

i dont really realize why and where this is happening, i guess it has something to do with relationtship registration

Possible implementation

add id column to default migration, or figure out why eloquent adds requiring "id" to its query and get rid of it

My environment

  • php 7.4
  • laravel 8.36.2
@belamov
Copy link
Author

belamov commented Apr 19, 2021

im not the only one who has this issue, see #13

@belamov
Copy link
Author

belamov commented Apr 19, 2021

ok so I found out those code in eloquent:

// If the model has an incrementing key, we can use the "insertGetId" method on
// the query builder, which will give us back the final inserted ID for this
// table from the database. Not all tables have to be incrementing though.
$attributes = $this->getAttributes();

if ($this->getIncrementing()) {
    $this->insertAndSetId($query, $attributes);
}

seems like we need to add this code to Favorite model

public function getIncrementing()
{
    return null;
}

ill add pr shortly

@BaraaDev
Copy link

App\Models\Course::isFavorited must return a relationship instance. (View: E:\laragon\www\Courses\resources\views\admin\courses\show.blade.php)

What is the solution to this error?

@mdbtekny
Copy link

mdbtekny commented Mar 2, 2022

Hey, have you resolved your problem?

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

No branches or pull requests

3 participants