Skip to content

Cannot eager load relation #187

@calebdw

Description

@calebdw

Hello!

Possibly related to #105

I have a HasOne relation:

class Run extends Model
{
    use \Awobaz\Compoships\Compoships;

    /** @return AwobazHasOne<Settings, $this> */
    public function settings(): AwobazHasOne
    {
        return $this->hasOne(
            Settings::class,
            ['item_id', 'coil_width'],
            ['item_id', 'coil_width'],
        );
    }
}

After a very tricky bug, I found that eager loading the relation causes it to be loaded as null despite the relation existing:

Run::firstOrFail()->settings; // exists
Run::with('settings')->firstOrFail()->settings; // does NOT exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions