Skip to content

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

@mesiarm

Description

@mesiarm
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions