Auto creation of dropdown box using foreign key?

edited July 2014 in Modules
I have done some researches before post. However the knowledge base seem still quite limited and hard for a beginner like me. For example now if i am creating a review module which is related to a product, so in the module i wrote

public $foreign_keys = array('product_id'=>'products_model');

In the create form of review, product id is displayed as a dropdown box. However it seems display the first two fields values of the table with id as value of the select and second column as the name of the select.

But i actually wanted to display the name of product which is located at the third column of the table

How can i customize this? Thanks

Comments

  • edited 12:56AM
    There is a method inherited from MY_Model that is used to generate that list. By default it will assume the label for the drop down is the second column. You could either move the field in the table or overwrite that method in you model as in below (where 'my_column' = 3rd column):
    public function options_list($key = NULL, $val = NULL, $where = array(), $order = TRUE) { if (empty($val)) $val = 'my_column'; return parent::options_list($key, $val, $where, $order); }
Sign In or Register to comment.