Modules display_field

edited July 2011 in Modules
Is it possible to set a modules config field: display_field to a field in another table?

I have an area where I'm managing the relationship between entities. None of the fields in this table are suitable for a display but one of the id fields (FK) links to a table that does.

Comments

  • edited 6:42AM
    Try adding that field in the model's _common_query() method with a select and join so it's available with basic find queries and see if that works:
    function _common_query() { parent::_common_query(); $this->db->select($this->table_name.'.* my_key_table.my_field'); $this->db->join('my_key_table', 'my_key_table.id = '.$this->table_name.'.my_key_table_id', 'left'); }
  • edited 6:42AM
    Thanks for that David,

    Doesn't quite crack it. I'm happy enough to keep hacking at it.

    So far:
    Problem comes from base_module_models::get_others which boils down to MY_Model::options_list

    options_list() seems to not use MY_Model::get() so it doesn't pick up _common_query

    I've dropped a:

    if (method_exists($this, '_common_query'))

    in there which is at least firing it.

    I'm picking it'll probably turn to custard with the validation of submits though.
  • edited September 2011
    In that case you can overwrite the option_list method in your model and apply any joins before calling the parent like so:
    function options_list(key, $val, $where, $order) { $this->db->join('join1', 'join1.ref_id = join2.id', 'left'); return parent::options_list($key, $val, $where, $order); }
  • edited 6:42AM
    I just did exactly that but added a concat() in there, the get_others list works perfectly fine... but this data is a mess/unsuitable for this approach, re-think needed!

    Cheers for your help.
  • edited 6:42AM
    in case someone had the same trouble figuring out why the above example is not returning entries in the dropdown, you need to

    return parent::options_list(...
  • edited 6:42AM
    I've updated the example above to help avoid confusion.
Sign In or Register to comment.