So, I have a `Product` model which `belongsTo('App\Tax')`. A `Product` may or may not be associated with a `Tax` (the `tax_id` fk in `Product` could be null).

The query below works fine as long as I have at least one `Product` associated with a `Tax`:

```
\App\Product::with("tax")->get()

```

It starts throwing the following exception, when none of the `Product`'s have associated `Tax`es:

```
Illuminate\Database\QueryException with message 'SQLSTATE[22P02]: Invalid text 
representation: 7 ERROR:  invalid input syntax for uuid: "0" (SQL: select * 
from "taxes" where "taxes"."id" in (0))'

```

While this exception is quite understandable, my question is how do I avoid this situation?

Note: The `tax.id` column is of postgres `uuid` type.

**EDIT 1**

I should explicitly mention that I'm trying to write a query to fetch all `Product`s, belonging to a particular `Organization`, whether they're associated with a `Tax` or not. 

The query above, works just fine as long as there is at least one `Product` associated with a `Tax`. It throws `QueryException` if all the products (1 or more), are not associated with any tax.

**EDIT 2**

So, I got a working solution, that doesn't seem quite right. I'm still open to a better solution. Here's how I got it to work:

```
// First just fetch all the products using whatever criterion
$products = $query
    ->orderBy ($params["orderBy"], $params["sortDir"])
    ->skip ($params["start"])
    ->take ($params["length"])
    ->get();

// Then, load the relation, if there's at least one product having
// that relation. 
// Solution requires one additional aggregate query per relation
// than a regular with() clause would have generated
$relations = array('purchase_tax', 'sale_tax', 'category');
foreach($relations as $relation) {
    $count = $org->products()
        ->whereHas($relation, function($query){
            $query->whereNotNull('id');
        })
        ->count();
    if ($count) {
        $products->load($relation);
    }
}

```

This gives me all products, even if none of them have the associated relations.