Setting display_field to a Join Table's field name.

edited August 2012 in Modules
I have a module, contacts_module, that creates an ordered list of data from another module, locations_module. The contact module contains three fields; id, a FK id to locations, and an order by field. I have included the locations' name field on teh contacts listing page so the end user knows which contact they are add/editing or deleting (otherwise the user only see the order by field). However, when deleting a contact item the contacts delete page page asks the user "You are about to delete the item: X" where X is the contacts.order_by. In order to make this output a little more meaningful to the end user I added the 'name' field (which is from the locations module, locations.name) to the contacts module configure (display_field = name). This works ("You are about to delete the item: Location Name") and this is, i am assuming, because I added a select with it to the contacts module common query method. Although, when I edit a contact item I receive an error "Unknown column 'name' in 'field list'" that I believe is triggered by the base_module_modle's method (#402) get_others' options_list call on display_field.

How can I add a joined table's field to display_name or update the base module delete method to use a joined table's fiels to identify which item is being deleted?

Thank you for your time, please let me know if I can provide any further details or clarification?

Comments

  • edited 9:27AM
    You can overwrite the "options_list" method in your model like so:
    function options_list($key = NULL, $val = NULL, $where = array(), $order = TRUE){ $this->db->join('locations', 'locations.id = contacts.location_id', 'left'); // change to match what you need parent::options_list($key, $val, $where, $order); }
    The options_list method does not run the _common_query upon execution so that join isn't there by default.
Sign In or Register to comment.