From 1560819c38bd6e1459b9668d83850952a10911a9 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 2 Nov 2005 02:19:41 +0000 Subject: [PATCH] [1306] Author: phpnut Date: 8:09:29 PM, Tuesday, November 01, 2005 [1304] Author: nate Date: 5:31:39 PM, Tuesday, November 01, 2005 Message: Fixed Ticket #77 [1295] Author: nate Date: 1:51:45 PM, Tuesday, November 01, 2005 Message: Added create() method to initialize model for new record [1305] Author: phpnut Date: 7:28:30 PM, Tuesday, November 01, 2005 Message: Fixed bug in the Model::findBySql(); Added fix for Ticket #111 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1307 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/libs/model/model.php | 31 +++++++++++++------ cake/libs/object.php | 1 - cake/libs/view/helpers/ajax.php | 2 +- .../libs/view/templates/layouts/default.thtml | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 236b4b1b0..be81f57aa 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.3.1131_alpha \ No newline at end of file +0.10.3.1307_alpha \ No newline at end of file diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index db8160f59..f2f051c63 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -657,6 +657,19 @@ class Model extends Object return $this->_tableInfo->findIn('name', $name); } +/** + * Initializes the model for writing a new record + * + * @return boolean True on success + */ + function create () + { + $this->id = false; + unset($this->data); + $this->data = array(); + } + + /** * Returns a list of fields from the database * @@ -1042,8 +1055,8 @@ class Model extends Object $oneToOneConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); $oneToOneOrder = $this->{$model}->{$this->currentModel.'_order'}; - $joins[] = "LEFT JOIN {$this->{$model}->table} AS $alias ON - $alias.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = {$this->name}.id" + $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON + `$alias`.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = {$this->name}.id" .($oneToOneConditions? " WHERE {$oneToOneConditions}":null) .($oneToOneOrder? " ORDER BY {$oneToOneOrder}": null); } @@ -1069,7 +1082,7 @@ class Model extends Object $belongsToOtherConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); $belongsToOtherOrder = $this->{$model}->{$this->currentModel.'_order'}; - $joins[] = "LEFT JOIN {$this->{$model}->table} AS $alias ON {$this->name}.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = $alias.id" + $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON {$this->name}.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = `$alias`.id" .($belongsToOtherConditions? " WHERE {$belongsToOtherConditions}":null) .($belongsToOtherOrder? " ORDER BY {$belongsToOtherOrder}": null); } @@ -1087,7 +1100,7 @@ class Model extends Object : ''; $sql = "SELECT " .join(', ', $f) - ." FROM {$this->table} AS {$this->name} {$joins}" + ." FROM {$this->table} AS `{$this->name}` {$joins}" .($conditions? " WHERE {$conditions}":null) .($order? " ORDER BY {$order}": null) .$limit_str; @@ -1145,7 +1158,7 @@ class Model extends Object $oneToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); $oneToManyOrder = $this->{$model}->{$this->currentModel.'_order'}; - $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS {$this->{$model}->name} + $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$this->{$model}->name}` WHERE ({$this->{$model}->{$this->currentModel.'_foreignkey'}}) = '{$value2['id']}'" .($oneToManyConditions? " WHERE {$oneToManyConditions}":null) .($oneToManyOrder? " ORDER BY {$oneToManyOrder}": null); @@ -1227,12 +1240,12 @@ class Model extends Object $manyToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); $manyToManyOrder = $this->{$model}->{$this->currentModel.'_order'}; - $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS {$this->{$model}->name} + $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$this->{$model}->name}` JOIN {$this->{$model}->{$this->currentModel.'_jointable'}} ON {$this->{$model}->{$this->currentModel.'_jointable'}}. {$this->{$model}->{$this->currentModel.'_foreignkey'}} = '$value2[id]' AND {$this->{$model}->{$this->currentModel.'_jointable'}}. - {$this->{$model}->{$this->currentModel.'_associationforeignkey'}} = {$this->{$model}->name} .id" + {$this->{$model}->{$this->currentModel.'_associationforeignkey'}} = `{$this->{$model}->name}` .id" .($manyToManyConditions? " WHERE {$manyToManyConditions}":null) .($manyToManyOrder? " ORDER BY {$manyToManyOrder}": null); @@ -1298,9 +1311,9 @@ class Model extends Object { foreach ($this->tableToModel as $key1 => $value1) { - if (isset($data[$key][Inflector::singularize($key1)])) + if (isset($data[$key][$key1])) { - $newData[$key][$value1] = $data[$key][Inflector::singularize($key1)]; + $newData[$key][$value1] = $data[$key][$key1]; } } } diff --git a/cake/libs/object.php b/cake/libs/object.php index 440bc0c19..85fabf424 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -114,7 +114,6 @@ class Object { $extra['render'] = 1; } - //$extra = array_merge($extra, array('bare'=>1)); $dispatcher =& new Dispatcher(); return $dispatcher->dispatch($url, $extra); } diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index a24183f90..eb3d6c949 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -159,7 +159,7 @@ class AjaxHelper extends Helper } else { - $html_options['onclick'] = $this->remoteFunction($options); + $html_options['onclick'] = $this->remoteFunction($options) . " return false;"; return $this->Html->link($title, $href, $html_options); } } diff --git a/cake/libs/view/templates/layouts/default.thtml b/cake/libs/view/templates/layouts/default.thtml index 4961c51fa..26692acfd 100644 --- a/cake/libs/view/templates/layouts/default.thtml +++ b/cake/libs/view/templates/layouts/default.thtml @@ -48,7 +48,7 @@
© 2005 CakePHP :: CakePHP Developers and Authors -

CakePHP version 0.10.3.1301_alpha

+

CakePHP version 0.10.3.1307_alpha

image('cake.power.png', array('alt'=>"CakePHP : Rapid Development Framework", 'border'=>"0"))?>