Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

Hello!

I'm having an issue with one of my eager loaded relationship. I'm trying to get a Document and its associated StatsDocument.

If I go

Document::first()->stat;

It works, I get the corresponding StatsDocument object, but if I go

Document::with('stat')->first()->stat;

I get null.

Relation stat is defined as follow in App\Http\Models\Document.php:

public function stat() 
{
    return $this->hasOne('App\Http\Models\StatsDocument', 'id', 'document_id');
}

I don't get what's wrong, all my other realtionships seem to be working perfectly fine while this one doesn't.

Any help is appreciated, Thank you

Last updated 3 years ago.
0

Any idea?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

SynRJ synrj Joined 3 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.