Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix #206 #498

Merged
merged 1 commit into from

2 participants

@jails
Collaborator

No description provided.

@jails
Collaborator

I'm safe... you can push me ;-)

@nateabele nateabele merged commit 04d11b2 into UnionOfRAD:data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2012
  1. @jails

    Fix #206

    jails authored
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 1 deletion.
  1. +15 −1 data/entity/Record.php
  2. +23 −0 tests/cases/data/source/DatabaseTest.php
View
16 data/entity/Record.php
@@ -13,6 +13,20 @@
* as columns in databases).
*/
class Record extends \lithium\data\Entity {
-}
+ /**
+ * Converts a `Record` object to another specified format.
+ *
+ * @param string $format The format used by default is `array`
+ * @param array $options
+ * @return mixed
+ */
+ public function to($format, array $options = array()) {
+ $defaults = array('handlers' => array(
+ 'stdClass' => function($item) { return $item; }
+ ));
+ $options += $defaults;
+ return parent::to($format, $options);
+ }
+}
?>
View
23 tests/cases/data/source/DatabaseTest.php
@@ -423,6 +423,29 @@ public function testUpdate() {
$expected = "UPDATE {mock_database_posts} SET";
$expected .= " {id} = 1, {title} = 'new post', {body} = 'the body' WHERE {id} = 1;";
$this->assertEqual($expected, $this->db->sql);
+
+ $entity = new Record(array(
+ 'model' => $this->_model,
+ 'data' => array('id' => 2, 'count' => (object) '{count} + 1'),
+ 'exists' => true
+ ));
+ $query = new Query(compact('entity') + array('type' => 'update'));
+ $result = $this->db->update($query);
+
+ $this->assertTrue($result);
+ $this->assertEqual(2, $query->entity()->id);
+
+ $expected = "UPDATE {mock_database_posts} SET";
+ $expected .= " {id} = 2, {count} = {count} + 1 WHERE {id} = 2;";
+ $this->assertEqual($expected, $this->db->sql);
+
+ $query = new Query(array(
+ 'type' => 'update',
+ 'data' => array('modified' => (object) 'NOW()'),
+ 'model' => $this->_model
+ ));
+ $sql = "UPDATE {mock_database_posts} SET {modified} = NOW();";
+ $this->assertEqual($sql, $this->db->renderCommand($query));
}
public function testDelete() {
Something went wrong with that request. Please try again.