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

Calling relationship with non existing foreign key returns null instead of throwing error #36353

Closed
mesiarm opened this issue Feb 22, 2021 · 1 comment

Comments

@mesiarm
Copy link

mesiarm commented Feb 22, 2021

  • Laravel Version: #.#.#
  • 8.27.0
  • PHP Version: #.#.#
  • 7.4.3
  • Database Driver & Version:
  • Postgres 13

Description:

Calling relationship with non existing foreign key returns null instead of throwing error.

Steps To Reproduce:

  1. Create relationship in model (for example $user->role)
  2. Fill custom non-existing foreign key (for example: (return $this->belongsTo(Role::class, 'x');)
  3. Create $user = new User(); object and set role_id property to existing role id.
  4. Calling relationship $user->role returns null (looks like role doesnt exist in database) instead of throwing error.
@taylorotwell
Copy link
Member

Feel free to PR a change in behavior you want to make - sounds like this would be a breaking change though.

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

2 participants