How to use alias in where clause with join with other table in grocery crud?

250 Views Asked by At

We need to use the :

$crud->where('session.active',"1");

in my condition, but when i add the above line it's give me error like : http://prntscr.com/nltp9i

This is my code :

$crud = new grocery_CRUD();
$crud->set_theme('bootstrap');
$crud->unset_jquery(); 
$crud->unset_bootstrap();
$crud->set_subject('Term');
$crud->set_table('term');
$crud->where('term.license_id',"$license_id");
$crud->where('session.active',"1");
$crud->columns('term_name', 'term',  'session_id','description','sort_order','active');
$crud->set_relation('session_id', 'session', 'session_name',array('session.license_id' => $this->license_id, 'session.active' => '1'));

So would you please let me know what is the wrong in it. And how can i make the where condition with session table?

We got this error :

Unknown column 'session.active' in 'where clause'

SELECT `term`.*, j7fc8ef54.session_name AS s7fc8ef54 FROM `term` LEFT JOIN `session` as `j7fc8ef54` ON `j7fc8ef54`.`session_id` = `term`.`session_id` WHERE `term`.`license_id` = '19259117593281' AND `session`.`active` = '1' LIMIT 10

Filename: models/Grocery_crud_model.php

Term table : Field

term_id         int(10) Auto Increment   
term_name       varchar(255) NULL    
term            varchar(255) NULL    
session_id      int(11) NULL     
description     text NULL    
sort_order      int(10) NULL     
active          int(1) NULL  
license_id      varchar(20)

Session table : Field

session_id      int(11) Auto Increment   
session_name    varchar(50)  
start_date      date     
end_date        date     
description     varchar(255)     
sort_order      int(2)   
active          int(1)   
license_id      varchar(20)

Thanks in advance.

0

There are 0 best solutions below