Merging fixes to trunk

Revision: [1778]
Fixing a few more bugs in the model code

Revision: [1777]
Fixes to Model::save() that allows saving a new record when primary key is not auto generated in database.
Added the DboSource::hasAny() back to the code.





git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1779 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-12 22:06:11 +00:00
parent 83d00fc93a
commit 7eb2555405
3 changed files with 18 additions and 5 deletions

View file

@ -161,7 +161,7 @@ class DboSource extends DataSource
*/
function one ($sql)
{
if ($this->query($sql))
if ($this->execute($sql))
{
return $this->fetchArray();
}
@ -760,6 +760,19 @@ class DboSource extends DataSource
$this->close();
parent::__destruct();
}
/**
* Checks if the specified table contains any record matching specified SQL
*
* @param string $table Name of table to look in
* @param string $sql SQL WHERE clause (condition only, not the "WHERE" part)
* @return boolean True if the table has a matching record, else false
*/
function hasAny($table, $sql)
{
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
return is_array($out)? $out[0]['count']: false;
}
}

View file

@ -919,11 +919,11 @@ class Model extends Object
if ($this->id)
{
$id = $this->id;
if (is_array($id) && count($id) == 1)
if (is_array($id))
{
$id = $id[0];
}
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->db->value($id));
return $this->db->hasAny($this->table,$this->primaryKey.'='.$this->db->value($id));
}
return false;
}

View file

@ -916,11 +916,11 @@ class Model extends Object
if ($this->id)
{
$id = $this->id;
if (is_array($id) && count($id) == 1)
if (is_array($id))
{
$id = $id[0];
}
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->db->value($id));
return $this->db->hasAny($this->table,$this->primaryKey.'='.$this->db->value($id));
}
return false;
}