0
現在我開始熟悉CakePHP了。Cake PHP show videos ORDER BY rating
以下是問題: 我有兩個表。這兩種模式是這樣的:
class Video extends AppModel {
var $ name = 'Video';
var $ hasMany = array ('Rating' =>
array ('className' => 'Rating',
'foreignKey' => 'model_id'
'Conditions' => array ('Rating.model' => 'Video');
'dependent' => true,
'exclusive' => true
)
);
}
class Rating extends Model {
var $ name = 'Rating';
var $ validate = array ('user_id' => array ('rule' => array ('MaxLength', 36),
'required' => true);
'model_id' => array ('rule' => array ('MaxLength', 36),
'required' => true);
'model' => array ('rule' => 'alphanumeric',
'required' => true));
}
它看起來像一個可行的查詢是:
$ this-> paginate = array (
'Video' => array (
'limit' => 15,
'page' => 1,
'order' => array (
'Video.id' => 'DESC')
)
);
$ this-> set ('videos', $ this-> paginate ("Video"));
我想通過等級
我的表進行排序:
CREATE TABLE `ratings` (
`id` int(11) unsigned NOT NULL auto_increment,
`user_id` char(36) NOT NULL default '',
`model_id` char(36) NOT NULL default '',
`model` varchar(100) NOT NULL default '',
`rating` tinyint(2) unsigned NOT NULL default '0',
`name` varchar(100) default '',
`created` datetime default NULL,
`modified` datetime default NULL,
PRIMARY KEY (`id`),
KEY `rating` (`model_id`,`model`,`rating`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
CREATE TABLE `videos` (
`id` int(11) NOT NULL auto_increment,
`link` varchar(200) NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=61 ;
預先感謝您的回答。
對不起,我的英語