⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation_n_n where on list view



carperolm

carperolm
  • profile picture
  • Member

Posted 01 March 2016 - 18:19 PM

Hi there,
 
I'm getting mad with this issue.
 
I have a n:n relation 
 
$where = "department_id = 1";
$crud->set_relation_n_n('departments','exp_dep','departments','exp_id','department_id','name, null, $where);
 
I would like to filter the listing view with a condition over a field in departments table departments.department_id
 
Everything works ok on edit and add views but is not working on listing state. I've been searching on forum but I didn't found any help.
 
If I use 
 
$crud->where('department_id',1);  I get a mysql error:
 
Unknown column 'department_id' in 'where clause'

 

Could anyone help me?

 

 

Thanks in advance.

 
 

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 02 March 2016 - 04:59 AM

Try icing along the table name of the department_id .. it may not belong to the same table on which the primary query is being fired. It may help you accordingly.


carperolm

carperolm
  • profile picture
  • Member

Posted 02 March 2016 - 18:19 PM

Hi Amit, Thanks for your fast answer. I've tried that before post the topic. Doesn't work either.


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 03 March 2016 - 09:00 AM

can u share the whole piece of code -- looking at the same, may be able to give some solution..!!


carperolm

carperolm
  • profile picture
  • Member

Posted 03 March 2016 - 11:28 AM

Hi Amit,

 

This is the basic code and it's working for the add and edit views, but not for the list view. I want to filter by departamento_id

$crud = new grocery_CRUD(); 
$crud->set_table('expedientes');
$crud->set_subject('Expedientes');
$where = "departamento_id = 1";
$crud->set_relation_n_n('departamentos','exped_depar','departamentos','expediente_id','departamento_id','name', null, $where);
$output = $crud->render();

Thanks


carperolm

carperolm
  • profile picture
  • Member

Posted 03 March 2016 - 12:24 PM

I found the solution here:

/topic/2367-pre-filtering-data/