-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Laravel
-
None
-
PHP Drivers
-
Not Needed
-
Unable to unset properties on an embedded document in a model using the Laravel MongoDB package. The query generated by the package does not correctly unset the specified property.
//Device class class Device extends Model { /** * The attributes that are mass assignable. * * @var array<string> */ protected $fillable = [ 'type', 'device_data' ]; public function device_data() { return $this->embedsOne(DeviceData::class); } }
// DeviceData class class DeviceData extends Model { /** * The attributes that are mass assignable. * * @var array<string> */ protected $fillable = [ 'field1', 'field2' ]; }
// code $device = Device::find('66926851514af3dfe500d659'); $data = $device->device_data; $data->unset('field1'); $data->update(); // However, the generated query is incorrect: db.devices.updateOne({"_id": ObjectId("66926851514af3dfe500d659")}, {"$set": {"device_data.$unset": {"field1": true}}})
Expected behavior:
db.devices.updateOne({"_id": ObjectId("66926851514af3dfe500d659")}, {"$unset": {"device_data.deviceType": true}});