My primary key is not "id"
Hi,
I'm rebuilding an existing site (previously built on an old Jommla! plateform) and I'm giving Fuel a whirl because I like what I've seen so far (easy module creation and easy to use backend).
All the table examples in the documentation are created with a primary key of "id". I'm working with an existing database using slightly different field names (i.e.: primary key is "key").
Is there a way to specifify this primary key difference when activating the module/creating the model, or do I have to rename my primary keys to "id"?
Maybe there is a very simlpe answer to this. Sorry if I've missed it. Thank you for your help.
Comments
Here is my model code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Divisions_model extends Base_module_model { protected $key_field = 'division_id'; protected $dsn = 'secondary'; function __construct() { parent::__construct('divisions'); } ...
If i change the primary key field name in the DIVISIONS table to "id", it works. However, naming it "division_id" does not, even when setting the key_field property as in above.
A Database Error Occurred Error Number: 1054 Unknown column 'id' in 'order clause' SELECT `divisions`.* FROM (`divisions`) ORDER BY `id` asc Filename: C:\wamp\www\1-durapac\fuel\codeigniter\database\DB_driver.php Line Number: 330
I was using a very basic model for my table and, since I didn't need any special formating or rendering, I hadn't defined the list_items method.
Setting it up and specifically declaring $col as "division_id" in its parameters got everything working.