更新时间:2023-02-02 22:54:32
p $ p> App :: uses('AppModel','Model');
并将其添加到类
var $ useTable ='vote';
它似乎尝试使用正确的名称。所以这可能不是一个问题。您可以验证您的数据源设置是否正确。
My app works with other models, but for some reason the "Vote" model cannot connect to the db table when I try to save to it. I've been at this for a couple days and I feel like I've tried everything!
here is my controller VoteController.php that calls the model (edited down for readability):
<?php
class VoteController extends AppController {
var $uses = array('Track', 'Vote');
function upvote() {
$this->autoRender = false;
$User = $this->auth();
if ($User) {
$track_id = @$this->params['id'];
$this->Vote->upvote($track_id, $User['User']['id']);
}
}
}
?>
here is the model vote.php:
<?php
App::uses('AppModel', 'Model');
class Vote extends AppModel {
var $name = 'Vote';
function upvote($id, $user_id) {
$VoteObject = array('Vote' => array(
'u_id' => $user_id,
't_id' => $id,
'upvote' => 1,
'downvote' => 0
));
$this->save($VoteObject);
}
}
?>
And of course, in my database, I have a table "votes" with columns id, u_id, t_id, upvote, and downvote. After everything executes, I get this error:
Missing Database Table
Error: Table votes for model Vote was not found in datasource default.
I've tried deleting the files in tmp, as well as renaming everything, printing out queries, etc, and I can't seem to get anywhere. Any help would be greatly appreciated!
try removing this line
App::uses('AppModel', 'Model');
and adding this to the class
var $useTable = 'votes';
It looks like it's trying to use the correct name. so that might not be an issue. Can you verify that your data source is setup correctly.