Level 1
The problem was with this:
$this->homeStorages->storageLoads()->toSql();
I was taking all records and relations to them, but when I do this:
$this->homeStorages->find(1)->storageLoads()->toSql();
It works just fine
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I created polymorphic relation and it works just fine, but when I query it I get query like this one:
select * from `storage_loads`
where `storage_loads`.`storage_id` is null and `storage_loads`.`storage_id` is not null and `storage_loads`.`storage_type` = ?
The problem is this part
where `storage_loads`.`storage_id` is null and `storage_loads`.`storage_id` is not null
This is my relation inside HomeStorages model
public function storageLoads()
{
return $this->morphMany( 'StorageLoads\Model', 'storage');
}
This is my query
$this->homeStorages->storageLoads()->toSql();
Why Laravel adds "is null and is not null"
The problem was with this:
$this->homeStorages->storageLoads()->toSql();
I was taking all records and relations to them, but when I do this:
$this->homeStorages->find(1)->storageLoads()->toSql();
It works just fine
Please or to participate in this conversation.