troelskn / laravel-fillable-relations

Provides HasFillableRelations trait to Eloquent models
64 stars 23 forks source link

SQLSTATE[HY000]: General error: 1364 Field 'xxx_id' doesn't have a default value #7

Open hugeps opened 6 years ago

hugeps commented 6 years ago

Basically looks like the foreign key field is not added into the SQL statement for a nested table element. Is there anything obvious I'm missing ?

$order = new Order($x); // Naturally items in array have no ids

table is linked as follows:

public function details()
{
    return $this->hasMany('App\Detail', 'order_id');
}

there's also belong to on detail:

public function order()
{
    return $this->belongsTo('App\Order','order_id');
}
troelskn commented 6 years ago

Thanks for reporting. Could you show the full code for each model class, as well as the database schema? (Run show create table $TABLENAME in a mysql prompt).