Eager Loading Null Nested Relationship Causes Memory Error when Null

Posted 3 months ago by hanzanati

I am eager loading a nested relationship and it works without issue.

However, when I eager load a nested relationship, where the 2nd relationship contains a null value, I get a memory exhausted error.

Here is the call from my Model. The profile.profileImage column is the null value.

  $position = (new MyModel())
            ->with(
                [
                    'profile',
                    'profile.user',
                    'profile.contact',
                    'profile.profileImage'
                ]
            )

Here is the relationship to the first relationship profile

   public function profile()
    {
        return $this->belongsTo('App\Models\Profile');
    }

And here is the relationship to profile.profileImage

    public function profileImage()
    {
        return $this->belongsTo('App\Models\FileModel');
    }

When the profile_image_id field is null in the profiles table, I get a memory exhausted error. When it contains a proper key to the files table, it works.

Any ideas?

Please sign in or create an account to participate in this conversation.