mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Fixing bug in Model::saveField, closes #4511
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6877 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d039ad32d4
commit
ea9e91218e
3 changed files with 33 additions and 2 deletions
|
@ -1011,7 +1011,12 @@ class Model extends Overloadable {
|
|||
* @see Model::save()
|
||||
*/
|
||||
function saveField($name, $value, $validate = false) {
|
||||
return $this->save(array($this->alias => array($name => $value)), $validate, array($name));
|
||||
$id = $this->id;
|
||||
$this->create(false);
|
||||
return $this->save(array($this->alias => array(
|
||||
$this->primaryKey => $id,
|
||||
$name => $value,
|
||||
)), $validate, array($name));
|
||||
}
|
||||
/**
|
||||
* Saves model data to the database. By default, validation occurs before save.
|
||||
|
|
|
@ -47,7 +47,8 @@ class ModelTest extends CakeTestCase {
|
|||
'core.syfile', 'core.image', 'core.device_type', 'core.device_type_category', 'core.feature_set', 'core.exterior_type_category',
|
||||
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
||||
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
|
||||
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field'
|
||||
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field',
|
||||
'core.node', 'core.dependency'
|
||||
);
|
||||
|
||||
function start() {
|
||||
|
@ -1603,6 +1604,17 @@ class ModelTest extends CakeTestCase {
|
|||
$TestModel->id = 1;
|
||||
$result = $TestModel->saveField('title', '', true);
|
||||
$this->assertFalse($result);
|
||||
|
||||
// Test bug #4511
|
||||
$this->loadFixtures('Node', 'Dependency');
|
||||
$Node =& new Node();
|
||||
$Node->set('id', 1);
|
||||
$result = $Node->read();
|
||||
$this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second'));
|
||||
|
||||
$Node->saveField('state', 10);
|
||||
$result = $Node->read();
|
||||
$this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second'));
|
||||
}
|
||||
|
||||
function testSaveWithCreate() {
|
||||
|
|
|
@ -395,6 +395,20 @@ class NodeNoAfterFind extends CakeTestModel {
|
|||
var $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true));
|
||||
var $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id'));
|
||||
}
|
||||
class Node extends CakeTestModel{
|
||||
var $name = 'Node';
|
||||
var $hasAndBelongsToMany = array(
|
||||
'ParentNode' => array(
|
||||
'className' => 'Node',
|
||||
'joinTable' => 'dependency',
|
||||
'foreignKey' => 'child_id',
|
||||
'associationForeignKey' => 'parent_id',
|
||||
)
|
||||
);
|
||||
}
|
||||
class Dependency extends CakeTestModel{
|
||||
var $name = 'Dependency';
|
||||
}
|
||||
class ModelA extends CakeTestModel {
|
||||
var $name = 'ModelA';
|
||||
var $useTable = 'apples';
|
||||
|
|
Loading…
Add table
Reference in a new issue