Closed
Description
- Laravel Version: 5.7.20
- PHP Version: 7.2.10
Description:
Since the update to 5.7.20 we have problems with our nullable morphTo relations. For example we have an relation for the last editor of an record which uses such relation because we support different kind of users. Means we have these 2 columns:
- updated_from_id
- updated_from_model
Our relation looks like the following:
public function updatedFrom()
{
return $this->morphTo( null , 'updated_from_model' , 'updated_from_id' );
}
Due to the fact that the database columns are nullable we expect that we can set the updated_from_model column to NULL. But if we do so, we get an SQL Error by calling the relation (e.g. for an article):
ErrorException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'articles.' in 'where clause'
(SQL: select * from `articles` where `articles`.`` = 0 and `articles`.`deleted_at` is null limit 1)
If we set the update_from_model to a valid model and leave the updated_from_id column 0 it works fine again.
Expected Result
Up to version 5.7.19 the result would be just NULL when calling the relation if the update_from_model is NULL.