Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Unanswered
w99910 asked this question in Q&A
Discussion options

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

You must be logged in to vote

Replies: 1 comment

Comment options

@w99910 are you able to solve it?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2280 on June 26, 2021 07:42.

AltStyle によって変換されたページ (->オリジナル) /