topclaudy / compoships

Multi-columns relationships for Laravel's Eloquent ORM
MIT License
1.1k stars 130 forks source link

HasOne results to an error #130

Open pndjike opened 2 years ago

pndjike commented 2 years ago

Error message

stripos(): Argument #1 ($haystack) must be of type string, array given

image

The code

use Awobaz\Compoships\Compoships;

public function transfer(): HasOne
    {
        return $this->hasOne(
            Transfer::class,
            ['withdraw_id', 'deposit_id'],
            ['id', 'id']
        );
    }

Version of the package : 2.1.2 Laravel Version : 8.6

undjike commented 2 years ago

I got this error using MySql

topclaudy commented 2 years ago

@undjike Did you import the trait in the Transfer class? Can you please show how you use the transfer relationship?

undjike commented 2 years ago

Yes, I imported the trait on both classes

topclaudy commented 2 years ago

@undjike Can you please show a usage of the transfer relationship?

undjike commented 2 years ago

@undjike Did you import the trait in the Transfer class? Can you please show how you use the transfer relationship?

I just eager loaded the transfer relation

$user->transactions()->with('transfer')->latest()->get()
topclaudy commented 2 years ago

@undjike A similar issue has been reported here https://github.com/topclaudy/compoships/issues/111. But I wasn't able to reproduce. Can you please share a simple Laravel project to reproduce the issue?

undjike commented 2 years ago

OK, I'll share later this evening.