Closed
Description
Hello guys, I`m having some trouble trying to figure out what is wrong with the code.
I have an hasOne relationship between Company and Partner.
Here are my Models:
App\Company.php
use Jenssegers\Mongodb\Eloquent\Model as Model;
class Company extends Model {
protected $collection = "company";
protected $primaryKey = "_id";
public function partner(){
return $this->hasOne(\App\Partner::class, "com_id");
}
}
App\Partner.php
use Jenssegers\Mongodb\Eloquent\Model as Model;
class Partner extends Model {
protected $collection = "partner";
protected $primaryKey = "_id";
protected $fillable = ["_id", "com_id", "email"];
}
If set foreign key from hasOne relationship pointing to primary key to model \App\Partner, It works like a charm.
But, If I set foreign key from relationship as com_id
, returns NULL.
Both, _id
and com_id
have the same value.
Am I doing something wrong?