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

HasOne doesnot work #2417

Unanswered
mirzaromi asked this question in General
Discussion options

  • Laravel-mongodb Version: 8.83.18
  • PHP Version: 7.4.11
  • Database Driver & Version: mongodb 4.4

Description: my relation ship doesnt work

Steps to reproduce

Expected behaviour

I want to store my data as a referece not embed but my relationship doesnt work

Actual behaviour

store data as reference

Logs: Insert log.txt here (if necessary)
``` namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Illuminate\Database\Eloquent\Model;

use Jenssegers\Mongodb\Eloquent\Model;

use App\Models\Parents;

class Student extends Model
{
use HasFactory;

protected $connection = "mongodb";
protected $collection = "student";
protected $guarded = ["_id"];
public function parents()
{
 return $this->hasOne(Parents::class);
}

}

You must be logged in to vote

Replies: 1 comment

Comment options

hello, I don't know if that is you case, but i had a non-working hasOne (hybrid)relation that failed because I was not setting the $connection property in the related model...

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
Labels
None yet
Converted from issue

This discussion was converted from issue #2415 on July 12, 2022 07:04.

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