Reputation: 5156
I have a db table called "packs" (pack_id, pack_name, pack_description, pack_image)
My packs.php model:
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Packs extends ORM {
}
My packs.php controller:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Packs extends Controller {
public function action_index($pack_name = null)
{
$view = new View('packs/index');
$this->response->body($view);
}
public function action_pack()
{
$pack_name = $this->request->param('id'); //get the packname from uri
$pack = ORM::factory('packs')->where('pack_name', $pack_name)->find();
print_r($pack);die;
$view = new View('packs/index');
$this->response->body($view);
}
} // End of file
Calling www.mysite.com/packs/pack/aPackName , Kohana throws this error:
Database_Exception [ 1146 ]: Table 'packs_db.packses' doesn't exist [ SHOW FULL COLUMNS FROM 'packses' ]
I checked my database.php conf file, everything's ok. Why da hell is kohana adding "es" at the end of the table name?? I am completely puzzled...
Upvotes: 0
Views: 963
Reputation: 31
Also had this problem, one of the solutions I found is to restrict set _table_names_plural variable to false. Something like this:
class Model_Admin_Users extends ORM
{
public function __construct()
{
$this->_table_names_plural = false;
parent::__construct();
}
}
Upvotes: 1
Reputation: 2262
It seems kohana is trying to be "smart" and guess what's the table name based on class name.
if you rename your model to Model_Pack
It should do the trick. Other solution is to give your model table name.
Upvotes: 1
Reputation: 19154
Your model should be named in singular noun Model_Pack
even though your table name is in plural. Those two rules are parts of Kohana ORM conventions.
p/s: the link points to conventions for Kohana 2.x but they are still applicable for 3.x with a few modifications.
Upvotes: 1