Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix #206 #494

Closed
wants to merge 1 commit into from

2 participants

@jails
Collaborator

No description provided.

@nateabele nateabele commented on the diff
data/model/Query.php
@@ -402,7 +402,10 @@ public function data($data = array()) {
$bind ? $bind->set($data) : $this->_data = array_merge($this->_data, $data);
return $this;
}
- $data = $bind ? $bind->data() : $this->_data;
+ $data = $bind ? $bind->to('array', array(
@nateabele Owner

Ternaries shouldn't be broken over multiple lines. Maybe you can just do:

$data = $this->_data;

if ($bind) {
    ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jails jails closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 26, 2012
  1. @jails

    Fix #206

    jails authored
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 1 deletion.
  1. +4 −1 data/model/Query.php
  2. +23 −0 tests/cases/data/source/DatabaseTest.php
View
5 data/model/Query.php
@@ -402,7 +402,10 @@ public function data($data = array()) {
$bind ? $bind->set($data) : $this->_data = array_merge($this->_data, $data);
return $this;
}
- $data = $bind ? $bind->data() : $this->_data;
+ $data = $bind ? $bind->to('array', array(
@nateabele Owner

Ternaries shouldn't be broken over multiple lines. Maybe you can just do:

$data = $this->_data;

if ($bind) {
    ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'handlers' => array(
+ 'stdClass' => function($item){return $item;}
+ ))) : $this->_data;
return ($list = $this->_config['whitelist']) ? array_intersect_key($data, $list) : $data;
}
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.