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

getForeignKey on Model does not depend on Primary Key #16370

Closed
ElMatella opened this issue Nov 11, 2016 · 3 comments
Closed

getForeignKey on Model does not depend on Primary Key #16370

ElMatella opened this issue Nov 11, 2016 · 3 comments

Comments

@ElMatella
Copy link
Contributor

  • Laravel Version: 5.3.20
  • PHP Version: 7.0

Description:

When setting the primary key on a model like that:

class Category extends Model
{
	protected $primaryKey = 'hash';
}

And then calling the getForeignKey() method still returns category_id. For the moment, the method is implemented like that:

public function getForeignKey()
{
    return Str::snake(class_basename($this)).'_id';
}

My proposition would just to make:

public function getForeignKey()
{
    return Str::snake(class_basename($this)).'_' . $this->primaryKey;
}

Is their a particular reason the foreign key does not depend on the primary one?

If not, I would be very happy to make a pull request...

@ntzm
Copy link
Contributor

ntzm commented Nov 11, 2016

Makes sense to me! Can imagine this would break a few builds though

@srmklive
Copy link
Contributor

srmklive commented Nov 14, 2016

@ElMatella Added a PR for this.

@themsaid
Copy link
Member

Moving the discussion to the PR.

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