DB problem

edited January 2014 in Modules
Hi. I just made a simple module through the command.

My database and tables are done. But when I go to my module in the modules menu, and then I click to create, this error appears: "Unknown column 'id' in 'field list". The module is named courses, my id column of my table courses is coursesID.

Why fuel is trying to get a field that is not in my database?

I put information in my table, now the main page of the module displays the information, however here appears a php error "Message: Undefined index: id". The problem must be related.

I tried to specify the fields with db->select() and it works in certain way, it only displays those fields, however it's still displaying the error.

How can I fix it?

Comments

  • edited 3:29PM
    Fuel assumes that the field is "id". To fix you'll need to do a select with an alias for ID in your list_items method:
    function list_items($limit = NULL, $offset = NULL, $col = 'name', $order = 'desc', $just_count = FALSE) { $this->db->select('coursesID as id, column1, column2, column3...etc'); $data = parent::list_items($limit, $offset, $col, $order, $just_count = FALSE); return $data; }
    Also, did you set the $key_field property on your model to coursesID?
  • edited 3:29PM
    Thank you for your answer. Sorry if my following question are dumb.

    But where do I have to set the $key_field?

    I did what you told me about the alias, and the main page of the module was not displaying errors. But when I clicked on create it's the same database error

    Then I set public $key_field = array('coursesID'); above the model's construct function. Finally the create page is working. But now the main page display the same php error that I mentioned.
  • edited 3:29PM
    To debug the query you can uncomment line 294 in the base_module_model.php file. That's the query that gets run to display the list view.

    Also, I'd set the $key_field to just 'coursesID' not wrapped in an array unless you have a compound key
  • edited 3:29PM
    Thank you so much for the answers in all my questions. It's been really helpful, I really appreciate it.
Sign In or Register to comment.