Skip to content

Relationships with non-primary keys #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CleytonBonamigo opened this issue May 31, 2017 · 0 comments · Fixed by #1837
Closed

Relationships with non-primary keys #1206

CleytonBonamigo opened this issue May 31, 2017 · 0 comments · Fixed by #1837

Comments

@CleytonBonamigo
Copy link

CleytonBonamigo commented May 31, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants