purekid / mongodm

MongoDB ORM that includes support for references,embed and multilevel inheritance.
MIT License
200 stars 47 forks source link

Add mutate method to model #10

Closed jrschumacher closed 11 years ago

jrschumacher commented 11 years ago

Add ability to mutate the data directly (i.e. use $inc and other MongoDB operators.) This protects data from loss where find -> mutate -> save would lose any transactions in between requests.

    // {... age: 16 ...}
    user = User::one();
    $id = $user->getId();
    $age = $user->age;

    $user->mutate(array('$inc' => array('age' => 1)));
    // {... age: 17 ...}

This could have serious effects such as:

    // {... age: 16 ...}
    $user->mutate(array('age' => 1));
    // { age: 16 }
purekid commented 11 years ago

A test failed in php-5.4.
$user = User::one() // here we got NULL from a fresh database ...but why in php-5.3 works. Orz...

jrschumacher commented 11 years ago

Idk... I develop with PHP 5.4 can you try retesting it manually via Travis?

purekid commented 11 years ago

It just failed in Travis , but I think will pass in our develop client. The problem is line 11 of MutatorTest.php . Travis in php 5.4 run this file first , so our User::one() just return a NULL value from database.

jrschumacher commented 11 years ago

@purekid ahh, I see. Makes sense I will make sure to create a setup routine for that at a later time.