Merging fixes and enhancements into trunk

Revision: [1855]
Forgot to merge changes between the PHP 5 and PHP 4 model classes

Revision: [1854]
Added fix to Model class so that setting var $useTable = false; will not try to create a datasource connection.
Added fix to basics.php in the file_put_contents function that would give a Warning :failed to open stream: File exists. 
This fix allows the file to be wrote to if it already exists.
Added fix for undefined notice in DboSource::generateAssociationQuery();
Added Model::$keyToTable to map foreign keys to thier proper tables so scaffold could work with them properly.
Fixed Controller::__generateAssociation() to use Model::$keyToTable.
Fixed layout issue with show view in scaffold.

Revision: [1853]
Added DataSource::buildSchemaQuery() which must be implemented in the child classes.
  This will be used to import a table schema.
Added DboMysql::buildSchemaQuery()
Added fix for Ticket #304 by reverting change made in [1825].
Reopened Ticket #286
Added fix for Ticket #310 

Revision: [1852]
Added fix for PHP Fatal error: Call to a member function on a non-object in... Controller::generateFieldNames() in PHP 4            
when using a HABTM association. 

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1856 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-22 05:12:28 +00:00
parent 660259640d
commit 26d7620f1b
10 changed files with 124 additions and 86 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.7.1851 RC 3
0.10.7.1856 RC 3

View file

@ -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);

View file

@ -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();

View file

@ -508,6 +508,11 @@ class DataSource extends Object
return $data;
}
function buildSchemaQuery($schema)
{
die("Implement in DBO");
}
/**
* Enter description here...
*

View file

@ -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'];

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}
}

View file

@ -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) . ";}");
}

View file

@ -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 "<dd>".$html->link($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";