Skip to content

Custom key for **belongsTo** relationship is not working. #2280

@w99910

Description

@w99910
  • Laravel-mongodb Version: ^3.8
  • PHP Version: 8.0
  • Database Driver & Version: mongodb driver - 3.6

Description:

I'm trying to implement belongsTo relationship with custom local key and foreign key.

Collection structure

posts

  • _id
  • accountId

alerts

  • _id
  • postId
  • type

Expected behaviour

Here we will match accountId in posts collection and postId in alerts collection.

App\Models\Post

public function alert(){
         return $this->belongsTo(App\Models\Alert::class,'postId','accountId');
     }

Actual behaviour

When I dd App\Models\Alert::first()->alert , it returns null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions