mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding Model::create() fix for Ticket #2200 and updating test case
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4628 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
08805f57b7
commit
222d19a43a
2 changed files with 28 additions and 7 deletions
|
@ -882,14 +882,18 @@ class Model extends Overloadable {
|
|||
$defaults = array();
|
||||
|
||||
$cols = $this->loadInfo();
|
||||
if (array_key_exists('default', $cols->value[0])) {
|
||||
$count = count($cols->value);
|
||||
$names = $cols->extract('{n}.name');
|
||||
$values = $cols->extract('{n}.default');
|
||||
|
||||
if (!empty($names) && !empty($values)) {
|
||||
$count = count($names);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($cols->value[$i]['name'] != $this->primaryKey) {
|
||||
$defaults[$cols->value[$i]['name']] = $cols->value[$i]['default'];
|
||||
if ($names[$i] != $this->primaryKey) {
|
||||
$defaults[$names[$i]] = $values[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->validationErrors = array();
|
||||
$this->set(array_filter($defaults));
|
||||
$this->set($data);
|
||||
|
@ -971,7 +975,7 @@ class Model extends Overloadable {
|
|||
* @return boolean True on success save
|
||||
*/
|
||||
function saveField($name, $value, $validate = false) {
|
||||
return $this->save(array($this->name => array($name => $value)), $validate);
|
||||
return $this->save(array($this->name => array($name => $value)), $validate, array($name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,6 +34,17 @@
|
|||
class Test extends Model {
|
||||
var $useTable = false;
|
||||
var $name = 'Test';
|
||||
|
||||
function loadInfo() {
|
||||
return new Set(array(
|
||||
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8'),
|
||||
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
array('name' => 'email', 'type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
array('name' => 'notes', 'type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''),
|
||||
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
|
@ -44,13 +55,19 @@
|
|||
class ModelTest extends UnitTestCase {
|
||||
|
||||
function setUp() {
|
||||
$this->test =& new Test();
|
||||
$this->Test =& new Test();
|
||||
}
|
||||
|
||||
function testIdentity() {
|
||||
$result = $this->test->name;
|
||||
$result = $this->Test->name;
|
||||
$expected = 'Test';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testCreation() {
|
||||
$expected = array('Test' => array('notes' => 'write some notes here'));
|
||||
$this->assertEqual($this->Test->create(), $expected);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue