staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

The where part of the statment is null #168

Closed stevewolfe555 closed 2 years ago

stevewolfe555 commented 2 years ago

Hello,

I have managed to get the SQL to look like what I know should work just the last part of it keep coming up null no matter what I have tried.

`class Product extends Model { use HasFactory; use \Staudenmeir\EloquentHasManyDeep\HasRelationships;

protected $guarded = [];

public function urlEntities(): BelongsToMany
{
    return $this->belongsToMany(UrlEntity::class)->using(UrlUrlEntity::class)->withPivot('priority_score');
}

public function urls()
{
    return $this->hasManyDeep(
        Url::class,
        ['product_url_entity', UrlUrlEntity::class], // Intermediate models and tables, beginning at the far parent (Product).
        [           
           'product_id', // Foreign key on the "product_url_entity" table.
           'url_id',      // Foreign key on the "url_entities" table (local key).
           'id'  // Foreign key on the "urls" table.
        ],
        [          
          'url_id',      // Local key on the "products" table.
          'url_entity_id', // Local key on the "product_url_entity" table (foreign key).
          'url_id'       // Local key on the "url_entity" table.
        ]
    );
}

}`

The above code generates this SQL

`SELECT

I am not sure where the "is null" is coming from but it needs to be the id of the product model.