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
FROM
urls
INNER JOIN url_url_entities ON url_url_entities.url_id = urls.id
INNER JOIN product_url_entity ON product_url_entity.url_entity_id = url_url_entities.url_id
WHERE
product_url_entity.product_id is null`
I am not sure where the "is null" is coming from but it needs to be the id of the product model.
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;
}`
The above code generates this SQL
`SELECT
FROM
urls
INNER JOINurl_url_entities
ONurl_url_entities
.url_id
=urls
.id
INNER JOINproduct_url_entity
ONproduct_url_entity
.url_entity_id
=url_url_entities
.url_id
WHEREproduct_url_entity
.product_id
is null`I am not sure where the "is null" is coming from but it needs to be the id of the product model.