我有一個Kohana(3.2)ORM查詢生成器的奇怪問題,我無法弄清楚什麼是錯的。我收到「錯誤的表名」例外情況:Kohana ORM - 錯誤的表名
Database_Exception [ 1103 ]: Incorrect table name '' [ SELECT ``.* FROM `` JOIN `user_plugins` ON (`user_plugins`.`plugin_id` = ``.`id`) WHERE `user_plugins`.`user_id` = '9' ]
正如您在查詢中看到的表爲空。
控制器:
$user = ORM::factory('user', Auth::instance()->get_user()->id);
if ($user->loaded())
{
$result = $user->plugin->find_all();
}
用戶模型:
class Model_User extends Useradmin_Model_User
{
protected $_has_many = array(
'plugin' => array('through' => 'user_plugins'),
);
...
user_plugin模型
class Model_user_plugin extends ORM
{
protected $_belongs_to = array(
'plugin' => array(),
'user' => array()
);
...
插件模型
class Model_Plugin extends ORM
{
protected $_has_many = array(
'user' => array('through' => 'user_plugins')
);
...
任何人都知道這裏有什麼可能是錯的? 任何幫助非常感謝!
什麼'Useradmin_Model_User'? PS。你爲什麼使用單數形式作爲關係名稱?它應該是'users','plugins'等。 – biakaveron
謝謝你的迴應。我使用Mixu Useradmin模塊進行一些小修改(主要是爲了使它與Kohana 3.2兼容)。你可以在這裏找到源代碼:https://github.com/mixu/useradmin/blob/master/classes/useradmin/model/user.php – Pelmered
你能告訴我var_dump($ user)'的結果嗎? – biakaveron