My primary key is not "id"

edited April 2012 in Modules
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

  • edited 10:43AM
    Set the key_field property on the model to the column name.
  • edited May 2012
    I gave that a try in my test site and, if I remember correctly, it worked. However, I can't get it to work now in my work project.

    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.
  • edited 10:43AM
    Where are you seeing the problem?
  • edited May 2012
    When I click on the Divisions module in the dashboard I get:
    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
  • edited 10:43AM
    The issue may be due to either your model's list_items method or the value of the module's table_headers parameter in your MY_fuel_module specifying "id" instead of "division_id" (if you used that to specify the columns instead of the list_items method for rendering the table).
  • edited 10:43AM
    Thanks admin, that did it!
    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.
Sign In or Register to comment.