staudenmeir / belongs-to-through

Laravel Eloquent BelongsToThrough relationships
MIT License
1.15k stars 88 forks source link

BelongsToThrough Local key doesnt seem to do anything #79

Closed Intrflex closed 1 year ago

Intrflex commented 1 year ago

Setting the local key appears to do nothing, i can see in the construct you ask for it but then nothing is ever done with it, i have three tables iot, tenant_iots & tenants, iot (imei) connects to tenants_iots (imei) and tenant has a relationship via tenant_id to id

class iot extends Model
{
    use BelongsToThrough;

    protected $guarded = ['id', 'created_at', 'updated_at'];

    protected $appends = ['tenant_id'];

    // belongs to tenant through iot_tenants table
    public function tenant()
    {
        return $this->belongsToThrough(Tenant::class, [TenantIot::class], 'imei');
    }

ive tried multiple variations and i just cant seem to get it to return anything since localkey isnt being respected

staudenmeir commented 1 year ago

Hi @Intrflex, Did you find a solution? $localKey is a legacy parameter and not used anymore. This package doesn't support all cases of custom keys, but you can use https://github.com/staudenmeir/eloquent-has-many-deep for unsupported cases instead.