Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy model update/remove #68

Open
jrschumacher opened this issue Jun 13, 2014 · 1 comment
Open

Lazy model update/remove #68

jrschumacher opened this issue Jun 13, 2014 · 1 comment
Milestone

Comments

@jrschumacher
Copy link
Collaborator

To improve speed to updating data I propose an optional model when updating data to lazily update by use of the findAndModify command.

Note: This option would make the assumption that you are content with the data you are saving. That is to say, when it gets executed it will replace data as specified.

Prototype

<?php

  // Goal:
  // 1. db.Person.findAndModify({_id: ObjectId('12345')}, {$set: {name: 'John Smith', age: 30}})
  // 2. Consistant API

  // defaults: sort = [], update = true, new = true
  $options = array(
    'sort' => array(),
    ['update' => true | 'remove' => true],
    'new' => true,
    'fields' => array(),
    'upsert' => false
  );

  Person::lazy($options); // or Person::findAndModify();
  $p = Person::id('12345');
  $p->name = 'John Smith';
  $p->age = 30;
  $p->save();

  //-- OR --

  // Create new methods (via trait) 
  $p = Person::pId('12345', $options);
  $p->name = 'John Smith';
  $p->age = 30;
  $p->save();

The choices we have from my perspective is either create some magic to set a flag for lazy/findAndModify/etc mode or clone existing functions.

@jrschumacher jrschumacher added this to the 2.0 milestone Jun 13, 2014
@jrschumacher
Copy link
Collaborator Author

I personally like the first option, but this has its downsides as it could lead to unintended consequences if the flag isn't removed in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant