diff --git a/VERSION.txt b/VERSION.txt index d58593ca4..ada54b4af 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.7.1851 RC 3 \ No newline at end of file +0.10.7.1856 RC 3 \ No newline at end of file diff --git a/cake/basics.php b/cake/basics.php index 5edd32651..bb5e58271 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -692,7 +692,7 @@ if (!function_exists('file_put_contents')) { $data = join('', $data); } - $res = @fopen($fileName, 'xb'); + $res = @fopen($fileName, 'w+b'); if ($res) { @fwrite($res, $data); diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 7d1fc9e0e..8fce0bba0 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -494,13 +494,14 @@ class Controller extends Object if ($objRegistryModel->isForeignKey($tabl['name'])) { $niceName = substr( $tabl['name'], 0, strpos( $tabl['name'], "_id" ) ); - $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName); - $fieldNames[ $tabl['name'] ]['table'] = Inflector::pluralize($niceName); + $fkNames = $this->{$model}->keyToTable[$tabl['name']]; + $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($fkNames[1]); + $fieldNames[ $tabl['name'] ]['table'] = $fkNames[0]; $association = array_search($fieldNames[ $tabl['name'] ]['table'],$this->{$model}->alias); $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName); - $fieldNames[ $tabl['name'] ]['model'] = $alias.$association; + $fieldNames[ $tabl['name'] ]['model'] = $fkNames[1]; $fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']]; - $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($niceName)]); + $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($fkNames[0])]); $fieldNames[ $tabl['name'] ]['foreignKey'] = true; } else if( 'created' != $tabl['name'] && 'updated' != $tabl['name'] ) @@ -660,7 +661,7 @@ class Controller extends Object $modelName = $relData['className']; $manyAssociation = $relation; $modelKeyM = Inflector::underscore($modelName); - $modelObject = new $modelName(); + $modelObject =& new $modelName(); if($doCreateOptions) { $otherDisplayField = $modelObject->getDisplayField(); diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 2f1a4c912..92309e1ec 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -508,6 +508,11 @@ class DataSource extends Object return $data; } + function buildSchemaQuery($schema) + { + die("Implement in DBO"); + } + /** * Enter description here... * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 6c25d10cf..0a45a4248 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -593,10 +593,14 @@ class DboSource extends DataSource case 'hasOne': if ($external) { - if ($assocData['finderQuery']) + if (isset($assocData['finderQuery'])) { return $assocData['finderQuery']; } + if(!isset($assocData['fields'])) + { + $assocData['fields'] = ''; + } $sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields'])); $sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias; $conditions = $queryData['conditions']; diff --git a/cake/libs/model/dbo/dbo_mysql.php b/cake/libs/model/dbo/dbo_mysql.php index 0aaad7e76..0c464c394 100644 --- a/cake/libs/model/dbo/dbo_mysql.php +++ b/cake/libs/model/dbo/dbo_mysql.php @@ -69,7 +69,7 @@ class DboMysql extends DboSource * * @var unknown_type */ - var $columns = array('primary_key' =>array('name' => 'int(11) DEFAULT NULL auto_increment'), + var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'), 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'int', 'limit' => '11'), @@ -285,14 +285,7 @@ class DboMysql extends DboSource { $data = mysql_real_escape_string($data, $this->connection); } - if($data != '') - { - $return = "'" . $data . "'"; - } - else - { - $return = "NULL"; - } + $return = "'" . $data . "'"; return $return; } @@ -536,5 +529,16 @@ class DboMysql extends DboSource return false; } } + + function buildSchemaQuery($schema) + { + $search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}', + '{FULLTEXT_MYSQL}', '{BOOLEAN}', '{UTF_8}'); + $replace = array('int(11) not null auto_increment', 'primary key', 'unsigned', + 'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'', + '/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */'); + $query = trim(str_replace($search, $replace, $schema)); + return $query; + } } ?> \ No newline at end of file diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index 8c84e4308..834df9e3f 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -181,6 +181,13 @@ class Model extends Object */ var $modelToTable = array(); +/** + * List of Foreign Key names to table used tables. Used for associations. + * + * @var array + */ + var $keyToTable = array(); + /** * Alias table names for model, for use in SQL JOIN statements. * @@ -300,28 +307,28 @@ class Model extends Object } $this->currentModel = Inflector::underscore($this->name); - $this->setDataSource($ds); ClassRegistry::addObject($this->currentModel, $this); $this->id = $id; if($this->useTable !== false) { - if ($table) - { - $tableName = $table; - } - else - { - if ($this->useTable) - { - $tableName = $this->useTable; - } - else - { - $tableName = Inflector::tableize($this->name); - } - } + $this->setDataSource($ds); + if ($table) + { + $tableName = $table; + } + else + { + if ($this->useTable) + { + $tableName = $this->useTable; + } + else + { + $tableName = Inflector::tableize($this->name); + } + } if (in_array('settableprefix', get_class_methods($this))) { @@ -336,28 +343,27 @@ class Model extends Object { $this->setSource($tableName); } - $this->__createLinks(); - } - if ($this->displayField == null) - { - if ($this->hasField('title')) - { - $this->displayField = 'title'; - } - if ($this->hasField('name')) - { - $this->displayField = 'name'; - } - if ($this->displayField == null) - { - $this->displayField = $this->primaryKey; - } + $this->__createLinks(); + + if ($this->displayField == null) + { + if ($this->hasField('title')) + { + $this->displayField = 'title'; + } + if ($this->hasField('name')) + { + $this->displayField = 'name'; + } + if ($this->displayField == null) + { + $this->displayField = $this->primaryKey; + } + } } } - - /** * PHP4 Only * @@ -489,6 +495,11 @@ class Model extends Object } $this->{$type}[$assocKey][$key] = $data; } + if($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) + { + $this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table; + $this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->name; + } } } } diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index f9227fe7a..131a61e05 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -181,6 +181,13 @@ class Model extends Object */ var $modelToTable = array(); +/** + * List of Foreign Key names to table used tables. Used for associations. + * + * @var array + */ + var $keyToTable = array(); + /** * Alias table names for model, for use in SQL JOIN statements. * @@ -300,28 +307,28 @@ class Model extends Object } $this->currentModel = Inflector::underscore($this->name); - $this->setDataSource($ds); ClassRegistry::addObject($this->currentModel, $this); $this->id = $id; if($this->useTable !== false) { - if ($table) - { - $tableName = $table; - } - else - { - if ($this->useTable) - { - $tableName = $this->useTable; - } - else - { - $tableName = Inflector::tableize($this->name); - } - } + $this->setDataSource($ds); + if ($table) + { + $tableName = $table; + } + else + { + if ($this->useTable) + { + $tableName = $this->useTable; + } + else + { + $tableName = Inflector::tableize($this->name); + } + } if (in_array('settableprefix', get_class_methods($this))) { @@ -336,23 +343,24 @@ class Model extends Object { $this->setSource($tableName); } - $this->__createLinks(); - } - if ($this->displayField == null) - { - if ($this->hasField('title')) - { - $this->displayField = 'title'; - } - if ($this->hasField('name')) - { - $this->displayField = 'name'; - } - if ($this->displayField == null) - { - $this->displayField = $this->primaryKey; - } + $this->__createLinks(); + + if ($this->displayField == null) + { + if ($this->hasField('title')) + { + $this->displayField = 'title'; + } + if ($this->hasField('name')) + { + $this->displayField = 'name'; + } + if ($this->displayField == null) + { + $this->displayField = $this->primaryKey; + } + } } } @@ -483,6 +491,11 @@ class Model extends Object } $this->{$type}[$assocKey][$key] = $data; } + if($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) + { + $this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table; + $this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->name; + } } } } diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index ff828c422..759f6a122 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -215,7 +215,7 @@ class AjaxHelper extends Helper if (isset($options['before'])) { - $func = "{$options['before']}; $function"; + $func = "{$options['before']}; $func"; } if (isset($options['after'])) { @@ -299,7 +299,7 @@ class AjaxHelper extends Helper $options['with'] = 'Form.serialize(this)'; } $options['url'] = $action; - + return $this->Html->formTag($htmlOptions['action'], $type, $htmlOptions) . $this->Javascript->event("$('".$htmlOptions['id']."')", "submit", "function(){" . $this->remoteFunction($options) . ";}"); } diff --git a/cake/libs/view/templates/scaffolds/show.thtml b/cake/libs/view/templates/scaffolds/show.thtml index b81c9126f..3325f7be5 100644 --- a/cake/libs/view/templates/scaffolds/show.thtml +++ b/cake/libs/view/templates/scaffolds/show.thtml @@ -46,7 +46,7 @@ $displayField = $otherModelObject->getDisplayField(); $displayText = $data[$alias][$displayField]; - if(!empty($data[$objModel->tableToModel[$objModel->table]][$field])) + if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]) && (isset($displayText))) { echo "