advanced.partial-update.txt 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. Title: Document Partial Updates
  2. ShortTitle: Partial updates
  3. Author: Dariusz Górecki <darek.krk@gmail.com>
  4. ---
  5. Since the `v1.3.5` You can do *partial updates* of documents.
  6. > [information]
  7. > Normally this extension, when using `EmongoDocument::save()` will always **replace** all contents of document
  8. in DB with the actual values of fields in Yours `EMongoDocument` instance (including all embedded documents etc.)
  9. You can pass to `EMongoDocument::update()` method a list of attributes for update, this will use an extreme efficient
  10. Mongo `$set` operator to update only listed fields, see example:
  11. ~~~
  12. [php]
  13. $model = ModelClass::model()->find(); // Find some document to work with
  14. // change some fields
  15. $model->field1 = 1;
  16. $model->field2 = 'value';
  17. // Optional: run validation, of changed fields:
  18. $model->validate(array('field1', 'field2'));
  19. // Use partial update
  20. $model->update(array('field1', 'field2'), true /* <- second parameter indicates to use partial update mechanism */);
  21. ~~~
  22. And thats it, this will only update those 2 fields, rest in DB will not be touched.