mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Removing hard-coded 'id' field from Model::_prepareUpdateFields. Fixes #6274.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8139 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
bf2829a896
commit
066629d566
3 changed files with 55 additions and 7 deletions
|
@ -1420,7 +1420,7 @@ class Model extends Overloadable {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$old = $this->find('first', array(
|
$old = $this->find('first', array(
|
||||||
'conditions' => array('id' => $this->id),
|
'conditions' => array($this->primaryKey => $this->id),
|
||||||
'fields' => array_values($included),
|
'fields' => array_values($included),
|
||||||
'recursive' => -1
|
'recursive' => -1
|
||||||
));
|
));
|
||||||
|
|
|
@ -63,9 +63,11 @@ class ModelTest extends CakeTestCase {
|
||||||
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
|
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
|
||||||
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
||||||
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
|
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
|
||||||
'core.counter_cache_user', 'core.counter_cache_post', 'core.uuidportfolio',
|
'core.counter_cache_user', 'core.counter_cache_post',
|
||||||
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid',
|
'core.counter_cache_user_nonstandard_primary_key',
|
||||||
'core.fruit', 'core.fruits_uuid_tag', 'core.uuid_tag'
|
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
|
||||||
|
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
|
||||||
|
'core.fruits_uuid_tag', 'core.uuid_tag'
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* start method
|
* start method
|
||||||
|
@ -3876,7 +3878,6 @@ class ModelTest extends CakeTestCase {
|
||||||
$result = $user[$User->alias]['post_count'];
|
$result = $user[$User->alias]['post_count'];
|
||||||
$expected = 3;
|
$expected = 3;
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Tests that counter caches are updated when records are deleted
|
* Tests that counter caches are updated when records are deleted
|
||||||
|
@ -3919,6 +3920,32 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->assertEqual($users[0]['User']['post_count'], 1);
|
$this->assertEqual($users[0]['User']['post_count'], 1);
|
||||||
$this->assertEqual($users[1]['User']['post_count'], 2);
|
$this->assertEqual($users[1]['User']['post_count'], 2);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Test counter cache with models that use a non-standard (i.e. not using 'id')
|
||||||
|
* as their primary key.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCounterCacheWithNonstandardPrimaryKey() {
|
||||||
|
$this->loadFixtures(
|
||||||
|
'CounterCacheUserNonstandardPrimaryKey',
|
||||||
|
'CounterCachePostNonstandardPrimaryKey'
|
||||||
|
);
|
||||||
|
|
||||||
|
$User = new CounterCacheUserNonstandardPrimaryKey();
|
||||||
|
$Post = new CounterCachePostNonstandardPrimaryKey();
|
||||||
|
|
||||||
|
$data = $Post->find('first', array(
|
||||||
|
'conditions' => array('pid' => 1),'recursive' => -1
|
||||||
|
));
|
||||||
|
$data[$Post->alias]['uid'] = 301;
|
||||||
|
$Post->save($data);
|
||||||
|
|
||||||
|
$users = $User->find('all',array('order' => 'User.uid'));
|
||||||
|
$this->assertEqual($users[0]['User']['post_count'], 1);
|
||||||
|
$this->assertEqual($users[1]['User']['post_count'], 2);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* test Counter Cache With Self Joining table
|
* test Counter Cache With Self Joining table
|
||||||
*
|
*
|
||||||
|
|
|
@ -2858,7 +2858,6 @@ class TranslatedArticle extends CakeTestModel {
|
||||||
class CounterCacheUser extends CakeTestModel {
|
class CounterCacheUser extends CakeTestModel {
|
||||||
var $name = 'CounterCacheUser';
|
var $name = 'CounterCacheUser';
|
||||||
var $alias = 'User';
|
var $alias = 'User';
|
||||||
var $fixture = 'counter_cache_user';
|
|
||||||
|
|
||||||
var $hasMany = array('Post' => array(
|
var $hasMany = array('Post' => array(
|
||||||
'className' => 'CounterCachePost',
|
'className' => 'CounterCachePost',
|
||||||
|
@ -2869,7 +2868,6 @@ class CounterCacheUser extends CakeTestModel {
|
||||||
class CounterCachePost extends CakeTestModel {
|
class CounterCachePost extends CakeTestModel {
|
||||||
var $name = 'CounterCachePost';
|
var $name = 'CounterCachePost';
|
||||||
var $alias = 'Post';
|
var $alias = 'Post';
|
||||||
var $fixture = 'counter_cache_user';
|
|
||||||
|
|
||||||
var $belongsTo = array('User' => array(
|
var $belongsTo = array('User' => array(
|
||||||
'className' => 'CounterCacheUser',
|
'className' => 'CounterCacheUser',
|
||||||
|
@ -2878,6 +2876,29 @@ class CounterCachePost extends CakeTestModel {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CounterCacheUserNonstandardPrimaryKey extends CakeTestModel {
|
||||||
|
var $name = 'CounterCacheUserNonstandardPrimaryKey';
|
||||||
|
var $alias = 'User';
|
||||||
|
var $primaryKey = 'uid';
|
||||||
|
|
||||||
|
var $hasMany = array('Post' => array(
|
||||||
|
'className' => 'CounterCachePostNonstandardPrimaryKey',
|
||||||
|
'foreignKey' => 'uid'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
class CounterCachePostNonstandardPrimaryKey extends CakeTestModel {
|
||||||
|
var $name = 'CounterCachePostNonstandardPrimaryKey';
|
||||||
|
var $alias = 'Post';
|
||||||
|
var $primaryKey = 'pid';
|
||||||
|
|
||||||
|
var $belongsTo = array('User' => array(
|
||||||
|
'className' => 'CounterCacheUserNonstandardPrimaryKey',
|
||||||
|
'foreignKey' => 'uid',
|
||||||
|
'counterCache' => true
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
class ArticleB extends CakeTestModel {
|
class ArticleB extends CakeTestModel {
|
||||||
var $name = 'ArticleB';
|
var $name = 'ArticleB';
|
||||||
var $useTable = 'articles';
|
var $useTable = 'articles';
|
||||||
|
|
Loading…
Reference in a new issue