Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing erroris due to bad rebase

  • Loading branch information...
commit 8c4cad86c2a0b09642d1376a1c403ab8485cb83c 1 parent 4b9e03c
@lorenzo lorenzo authored
View
47 cake/libs/model/datasources/dbo_source.php
@@ -420,35 +420,6 @@ function fetchVirtualField(&$result) {
}
/**
- * Modifies $result array to place virtual fields in model entry where they belongs to
- *
- * @param array $resut REference to the fetched row
- * @return void
- */
- function fetchVirtualField(&$result) {
- if (isset($result[0]) && is_array($result[0])) {
- foreach ($result[0] as $field => $value) {
- if (strpos($field,'__') === false) {
- continue;
- }
- list($alias,$virtual) = explode('__',$field);
-
- if (!ClassRegistry::isKeySet($alias)) {
- retrun;
- }
- $model = ClassRegistry::getObject($alias);
- if (isset($model->virtualFields[$virtual])) {
- $result[$alias][$virtual] = $value;
- unset($result[0][$field]);
- }
- }
- if (empty($result[0])) {
- unset($result[0]);
- }
- }
- }
-
-/**
* Returns a single field of the first of query results for a given SQL query, or false if empty.
*
* @param string $name Name of the field
@@ -1823,24 +1794,6 @@ function _constructVirtualFields(&$model,$alias,$fields) {
}
/**
- * Converts model virtual fields into sql expressions to be fetched later
- *
- * @param Model $model
- * @param string $alias Alias tablename
- * @param mixed $fields virtual fields to be used on query
- * @return array
- */
- function _constructVirtualFields(&$model,$alias,$fields) {
- $virtual = array();
- foreach ($fields as $field) {
- $virtualField = $this->name("{$alias}__{$field}");
- $expression = $model->virtualFields[$field];
- $virtual[] = $expression . " {$this->alias} {$virtualField}";
- }
- return $virtual;
- }
-
-/**
* Generates the fields list of an SQL query.
*
* @param Model $model
View
8 cake/libs/model/model.php
@@ -1049,7 +1049,7 @@ function hasField($name, $checkVirtual = false) {
* @access public
*/
function isVirtualField($field) {
- return !empty($this->virtualFields) && array_key_exists($field,$this->virtualFields);
+ return !empty($this->virtualFields) && is_string($field) && array_key_exists($field,$this->virtualFields);
}
/**
@@ -1170,9 +1170,9 @@ function field($name, $conditions = null, $order = null) {
return $data[$name[0]][$name[1]];
}
}
- if (!empty($data[0])) {
- $name = key($data[0]);
- return $data[0][$name];
+ if (isset($data[0]) && count($data[0]) > 0) {
+ return array_shift($data[0]);
+ }
} else {
return false;
}
View
160 cake/tests/cases/libs/model/model_read.test.php
@@ -26,123 +26,6 @@
*/
class ModelReadTest extends BaseModelTest {
-/**
- * testVirtualFields()
- *
- * Test correct fetching of virtual fields
- * currently is not possible to do Relation.virtualField
- *
- * @access public
- * @return void
- */
- function testVirtualFields() {
- $this->loadFixtures('Post','Author');
- $Post = ClassRegistry::init('Post');
- $Post->virtualFields = array('two' => "1 + 1");
- $result = $Post->find('first');
- $this->assertEqual($result['Post']['two'],2);
-
- $Post->Author->virtualFields = array('false' => '1 = 2');
- $result = $Post->find('first');
- $this->assertEqual($result['Post']['two'],2);
- $this->assertEqual($result['Author']['false'],false);
-
- $result = $Post->find('first',array('fields' => array('author_id')));
- $this->assertFalse(isset($result['Post']['two']));
- $this->assertFalse(isset($result['Author']['false']));
-
- $result = $Post->find('first',array('fields' => array('author_id','two')));
- $this->assertEqual($result['Post']['two'],2);
- $this->assertFalse(isset($result['Author']['false']));
-
- $result = $Post->find('first',array('fields' => array('two')));
- $this->assertEqual($result['Post']['two'],2);
-
- $Post->id = 1;
- $result = $Post->field('two');
- $this->assertEqual($result,2);
-
- $result = $Post->find('first',array(
- 'conditions' => array('two' => 2),
- 'limit' => 1
- ));
- $this->assertEqual($result['Post']['two'],2);
-
- $result = $Post->find('first',array(
- 'conditions' => array('two <' => 3),
- 'limit' => 1
- ));
- $this->assertEqual($result['Post']['two'],2);
-
- $result = $Post->find('first',array(
- 'conditions' => array('NOT' => array('two >' => 3)),
- 'limit' => 1
- ));
- $this->assertEqual($result['Post']['two'],2);
-
- $dbo =& $Post->getDataSource();
- $Post->virtualFields = array('other_field' => $dbo->name('Post.id') . ' + 1');
- $result = $Post->find('first',array(
- 'conditions' => array('other_field' => 3),
- 'limit' => 1
- ));
- $this->assertEqual($result['Post']['id'],2);
-
- $Post->virtualFields = array('other_field' => $dbo->name('Post.id') . ' + 1');
- $result = $Post->find('all',array(
- 'fields' => array($dbo->calculate($Post,'max',array('other_field')))
- ));
- $this->assertEqual($result[0][0]['other_field'],4);
-
- ClassRegistry::flush();
- $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'),'Model');
- $Writing->virtualFields = array('two' => "1 + 1");
- $result = $Writing->find('first');
- $this->assertEqual($result['Writing']['two'],2);
- }
-
-/**
- * testVirtualFields()
- *
- * Test correct fetching of virtual fields
- * currently is not possible to do Relation.virtualField
- *
- * @access public
- * @return void
- */
- function testVirtualFields() {
- $this->loadFixtures('Post','Author');
- $Post = ClassRegistry::init('Post');
- $Post->virtualFields = array('two' => "1 + 1");
- $result = $Post->find('first');
- $this->assertEqual($result['Post']['two'],2);
-
- $Post->Author->virtualFields = array('false' => '1 = 2');
- $result = $Post->find('first');
- $this->assertEqual($result['Post']['two'],2);
- $this->assertEqual($result['Author']['false'],false);
-
- $result = $Post->find('first',array('fields' => array('author_id')));
- $this->assertFalse(isset($result['Post']['two']));
- $this->assertFalse(isset($result['Author']['false']));
-
- $result = $Post->find('first',array('fields' => array('author_id','two')));
- $this->assertEqual($result['Post']['two'],2);
- $this->assertFalse(isset($result['Author']['false']));
-
- $result = $Post->find('first',array('fields' => array('two')));
- $this->assertEqual($result['Post']['two'],2);
-
- $Post->id = 1;
- $result = $Post->field('two');
- $this->assertEqual($result,2);
-
- ClassRegistry::flush();
- $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'),'Model');
- $Writing->virtualFields = array('two' => "1 + 1");
- $result = $Writing->find('first');
- $this->assertEqual($result['Writing']['two'],2);
- }
/**
* testFetchingNonUniqueFKJoinTableRecords()
@@ -7279,5 +7162,48 @@ function testFindQueryTypeInCallbacks() {
$comments = $Comment->find('first');
$this->assertEqual($comments['Comment']['querytype'], 'first');
}
+
+/**
+ * testVirtualFields()
+ *
+ * Test correct fetching of virtual fields
+ * currently is not possible to do Relation.virtualField
+ *
+ * @access public
+ * @return void
+ */
+ function testVirtualFields() {
+ $this->loadFixtures('Post','Author');
+ $Post = ClassRegistry::init('Post');
+ $Post->virtualFields = array('two' => "1 + 1");
+ $result = $Post->find('first');
+ $this->assertEqual($result['Post']['two'],2);
+
+ $Post->Author->virtualFields = array('false' => '1 = 2');
+ $result = $Post->find('first');
+ $this->assertEqual($result['Post']['two'],2);
+ $this->assertEqual($result['Author']['false'],false);
+
+ $result = $Post->find('first',array('fields' => array('author_id')));
+ $this->assertFalse(isset($result['Post']['two']));
+ $this->assertFalse(isset($result['Author']['false']));
+
+ $result = $Post->find('first',array('fields' => array('author_id','two')));
+ $this->assertEqual($result['Post']['two'],2);
+ $this->assertFalse(isset($result['Author']['false']));
+
+ $result = $Post->find('first',array('fields' => array('two')));
+ $this->assertEqual($result['Post']['two'],2);
+
+ $Post->id = 1;
+ $result = $Post->field('two');
+ $this->assertEqual($result,2);
+
+ ClassRegistry::flush();
+ $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'),'Model');
+ $Writing->virtualFields = array('two' => "1 + 1");
+ $result = $Writing->find('first');
+ $this->assertEqual($result['Writing']['two'],2);
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.