Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-211

Unable to unset properties on an embedded document

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • laravel-4.7.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • PHP Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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}}); 

       

       

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            muhammad.memon@ionyx.com.au Muhammad Memon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: