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

[5.4] Undocummented breaking change for eloquent relationship foreign key name #17503

Closed
CyrilMazur opened this issue Jan 24, 2017 · 3 comments
Closed

Comments

@CyrilMazur
Copy link
Contributor

When omitting the foreign key name in the definition of a relationship, like so

    public function profile()
    {
        return $this->belongsTo(Profile::class);
    }

the foreign key name is automatically generated by Laravel, but the way it generates has changed between 5.3 and 5.4.

In 5.3:

$foreignKey = Str::snake($relation).'_id';

(https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L776)

In 5.4:

$foreignKey = Str::snake($relation).'_'.$instance->getKeyName();

(https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php#L112)

This breaks when a table is using a primary key different from "id".

@ntzm
Copy link
Contributor

ntzm commented Jan 24, 2017

You can submit a PR for the docs here

@GrahamCampbell
Copy link
Member

Thanks for reporting.

@taylorotwell
Copy link
Member

Documented.

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

4 participants