SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    0 Post(s)
    0 Thread(s)

    How to do a Join Table in a CI_Bonfire module?

    I love how I can feed the CodeBuilder a table out of my data base and it'll build 90 percent of the code for me, I mainly just need to rearrange it to what I need. The implied architecture is one table per a module. Well now I need to perform my second "join" ever... and the first one was confusing to get right. I'm still not sure about the whole left or right join, but that's for another forum. I created a second module, just to copy the model file back to the first module and then call both models in the constructor...

    Code PHP:
    public function __construct()
        $this->load->model('customers_model', null, true);
        $this->load->model('work_log_model', null, true);
        Template::set_block('sub_nav', 'reports/_sub_nav');
        Assets::add_module_js('work_log', 'work_log.js');
    after loading both models I attempt to "join" them...

    Code PHP:
    public function index()
        // Deleting anything?
        if (isset($_POST['delete']))
            $checked = $this->input->post('checked');
            if (is_array($checked) && count($checked))
                $result = FALSE;
                foreach ($checked as $pid)
                    $result = $this->work_log_model->delete($pid);
                if ($result)
                    Template::set_message(count($checked) .' '. lang('work_log_delete_success'), 'success');
                    Template::set_message(lang('work_log_delete_failure') . $this->work_log_model->error, 'error');
        $this->work_log_model->join('bf_daily_gol', 'Property_ID = Property_ID');
        $records = $this->work_log_model->where('Customer_ID', $this->current_user->Customer_ID)->order_by('Done', 'desc')->find_all();
        Template::set('records', $records);
        Template::set('toolbar_title', 'Manage Work Log');
    So far I'm getting a 1066 Error... Not unique table/alias: 'bf_daily_gol'

    Can anyone suggest how I should be doing this?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Augusta, Georgia, United States
    16 Post(s)
    4 Thread(s)
    Well I'm not familiar with the CI ActiveRecord interface but after taking a glance at the docs it looks like Property_ID is ambiguous. In order to resolve the issue simply add the table name before each one.

    PHP Code:
    $this->work_log_model->join('bf_daily_gol''bf_users.Property_ID = bf_daily_gol.Property_ID'); 
    The only code I hate more than my own is everyone else's.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts