Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Join in _common_query() used in find_all()?

edited December 2016 in Modules

I would like to access data from a joined table (SERIES) when I access my model (EMISSIONS) using the find_all() method. Am I correct in understanding that I can do this by declaring the join in the common_query() method of my model? If so, I can't seem to get it to work.

Here is the find_all() used in my global variables file:

$vars ['emissions'] = $CI->emissions_model->find_all(array(),null,3,null,'array');

Here is my EMISSIONS model file:

class Emissions_model extends Base_module_model { protected $key_field = 'em_id'; function __construct() { parent::__construct('emissions'); // table name } function list_items($limit = NULL, $offset = NULL, $col = 'em_titre', $order = 'asc') { $this->db->join('series', 'series.ser_identifiant = emissions.em_identifiant', 'left'); $this->db->select('em_id, em_titre "TITRE DE L\'\ÉMISSION", ser_nom AS SÉRIE, em_annee AS ANNÉE, em_mois AS MOIS, em_jour AS JOUR', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function _common_query() { parent::_common_query(); // to do active and published $this->db->join('series', 'series.ser_identifiant = emissions.em_identifiant', 'left'); $this->db->order_by('em_lastmod asc'); } } class Emission_model extends Base_module_record { function get_emission_formatted() { } } ?>

Using this, nothing from SERIES is contained in the $emissions array.
The _common_query is working when used only for the "order_by" part...

What am I missing?

Thank you!


Sign In or Register to comment.