diff options
Diffstat (limited to 'models/Entry.php')
-rw-r--r-- | models/Entry.php | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/models/Entry.php b/models/Entry.php index e84d438..12a3035 100644 --- a/models/Entry.php +++ b/models/Entry.php @@ -10,9 +10,9 @@ Class entry extends \lithium\data\Model { public static function __init() { parent::__init(); - //Validators go here } + public $_schema = array('_id' => array('type' => 'id')); public $validates = array( 'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'), 'my_start_date' => array('date', 'message' => 'Please enter a valid date'), @@ -20,7 +20,7 @@ Class entry extends \lithium\data\Model { 'my_score' => array(array('inRange' => array('min' => 0, 'max' => '10'), 'message' => 'Enter a valid score'), array('numeric', 'message' => 'Please enter a number')), //'my_status' => array('isValidStatus', 'message' => 'please enter valid status'), - 'my_times_watched' => array('numeric', 'message' => 'This must be a number') + 'my_times_watched' => array('numeric', 'message' => 'This must be a number'), ); //Add timestamping to entries. :TODO: @@ -29,36 +29,38 @@ Class entry extends \lithium\data\Model { - /* public function add($entity, $username) { - var_dump($entity->_data); - exit(); - $updateData = array('$push' => array('animelist' => $entity)); - $conditions = array('username' => $username); + $updateData = array('$push' => array('animelist' => $entity->data())); + $conditions = compact('username'); $result = Entry::update($updateData, $conditions, array('atomic' => false)); return $result; } - */ + /* //Got lazy, the proper way to do it is above, but needs a bit of fiddling. - //The below code works, but forces mongo to resave the entire record, which tags + //The below code works, but forces mongo to resave the entire record, which takes //longer than just updating what has chaged. public function add($entity, $username) { $user = User::find('first', array('conditions' => compact('username'))); $entity->created_on = new MongoDate(); $entity->updated_on = new MongoDate(); + $user->animelist[] = $entity; - if (Validator::check($entity->data(), $this->validates, array('skipEmpty' => 'true'))) { - return $user->save(null, array('validate' => false)); - } + //if (Validator::check($entity->data(), $this->validates, array('skipEmpty' => 'true'))) { + $return = $user->save(null, array('validate' => false)); + var_dump($entity); + exit(); + /* else { return false; } + } + */ public function edit($entity, $username) { |