TitasGailius / nova-search-relations

This package allow you to include relationship columns into Laravel Nova search query.
Other
352 stars 33 forks source link

Search relation on another connection 'Base table or view not found' #30

Closed preliot closed 3 years ago

preliot commented 3 years ago

Also having issues with a search on relations on another connection. In other issues (https://github.com/TitasGailius/nova-search-relations/issues/22, https://github.com/TitasGailius/nova-search-relations/issues/28) you've said the packages adds a bunch of whereHas scopes.

But why doens't it work? All my code seems to work fine, except when i try to search on relations on other connections. For example, when i search in my nova resource SupplierProduct for a supplier, i get a 'Base table or view not found'. The resulting query shows me that the connection is not added to the supplier.

Message

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'products-supplier.suppliers' doesn't exist

(This shows the wrong connection is used for this table)

Model SupplierProduct:

class SupplierProduct extends Model {

    protected $connection = 'products-supplier';

    protected $foreignKey = 'supplier_product_id';

    protected $table = 'supplier_products';

    //...

    public function supplier(): Relations\BelongsTo {
        return $this->belongsTo(Supplier::class);
}

Model Supplier:

class Supplier extends Model {

//doesn't matter if i provide the default 'mysql' connection

    protected $table = 'suppliers';
}

Questions

  1. Is this a Laravel bug/feature or someting i'm missing?
  2. If this is not your package, do you have a suggestion what i should do?
maximesahagian commented 3 years ago

Did you solve it? Same issue

preliot commented 3 years ago

Had a week off :)

Unfortunatly no. The author of this package suggests it's a Laravel issue (see linked issues), although i'm pretty sure something is wrong. Because it was not critical for our project we just ignored this issue.

Would be nice though if it was fixed.