After a debugging session, I figured out why my model was not being updated correctly. In my model, I had not defined a $fillable array. I generally opt for setting $guarded fields in stead:
It turns out that when your model implements the LocationModel behavior, that sets an array of fillable properties, which is not compatible with the above. I'd propose the following fix in the LocationModel constructor:
/**
* Constructor
*/
public function __construct($model)
{
parent::__construct($model);
if (!empty($model->getFillable())) {
$model->addFillable([
'country',
'country_id',
'country_code',
'state',
'state_id',
'state_code'
]);
}
$model->belongsTo['country'] = ['RainLab\Location\Models\Country'];
$model->belongsTo['state'] = ['RainLab\Location\Models\State'];
}
This way, if the model does define $fillable properties, the location properties are added as fillable. If not, they would be fillable by default unless the developer explicitly blacklists them using the $guarded array.
I have created a PR (#53) to implement the above.
After a debugging session, I figured out why my model was not being updated correctly. In my model, I had not defined a
$fillablearray. I generally opt for setting$guardedfields in stead:It turns out that when your model implements the
LocationModelbehavior, that sets an array offillableproperties, which is not compatible with the above. I'd propose the following fix in theLocationModelconstructor:This way, if the model does define
$fillableproperties, the location properties are added as fillable. If not, they would be fillable by default unless the developer explicitly blacklists them using the$guardedarray.I have created a PR (#53) to implement the above.