Kohana ORM-错误的表名 [英] Kohana ORM - Incorrect table name

查看:99
本文介绍了Kohana ORM-错误的表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Kohana(3.2)ORM查询生成器中遇到了一个奇怪的问题,我不知道出了什么问题.我收到表名不正确"的异常:

I have a weird problem with the Kohana (3.2) ORM query builder and i can't figure out what is wrong. I get "Incorrect table name" exception:

  Database_Exception [ 1103 ]: Incorrect table name '' [ SELECT ``.* FROM `` JOIN `user_plugins` ON (`user_plugins`.`plugin_id` = ``.`id`) WHERE `user_plugins`.`user_id` = '9' ]

您可以看到查询中的表为空.

As you can see the table is empty in the query.

控制器:

  $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模型

user_plugin Model

  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')
     );
  ...

任何人都知道这里可能有什么问题吗? 任何帮助,我们将不胜感激!

Anyone got any idea what could be wrong here? Any help is very appreciated!

推荐答案

这应该是用户模型

class Model_User extends Useradmin_Model_User
{
   protected $_has_many = array(
      'plugin' => array('model' => 'plugin', 'through' => 'user_plugins'),
   );
...

这应该是插件模型

class Model_Plugin extends ORM
{
    protected $_has_many = array(
        'user' => array('model' => 'user', 'through' => 'user_plugins')
    );

您根本不需要user_plugin模型,两个模型中的"user_plugins"都是指表名,而不是模型名.只要确保您具有带user_plugins的表,该表具有以下字段,

You don't need user_plugin Model at all, the "user_plugins" in both models refers to the table name, not the model name. Just make sure you have the table with user_plugins that have following fields,

id,user_id,plugin_id

id, user_id, plugin_id

我希望这会有所帮助.

这篇关于Kohana ORM-错误的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆