Jump to content

set_relation and table where

  • Please log in to reply
2 replies to this topic

#1 HumbleMonk



  • Members
  • PipPip
  • 25 posts

Posted 09 May 2012 - 05:54 PM

I am trying to use a table where and set_relation on the same crud table and am having difficulties.

I have two tables, table_a and table_b. Both have a 'type' field. I am filtering table_a by the type column and then setting a relation to a field in table_b.

Here is the code:

$crud = new grocery_CRUD();
$crud->where('type', 'food');


$crud->set_relation('contact', 'table_b', '{firstName} {lastName}');      
$output = $crud->render();    
$output = (array)$output;       	

The problem is that this returns a database error saying that 'type' on the where() is ambiguous. OK, no problem, I've had this error before on callback_column and followed this solution to get a unique field name. The problem is that I tried to use that on the where clause:

$crud->where($this->unique_field_name('type'), 'food');

And that returns a database error of 'unknown column' for the where().

Is there any solution besides changing the name of one of the fields?

#2 web-johnny


    grocery CRUD Author

  • Administrators
  • 1,025 posts
  • LocationLondon

Posted 09 May 2012 - 06:30 PM

This should work:

$crud->where('table_a.type', 'food');

Posted Image

#3 HumbleMonk



  • Members
  • PipPip
  • 25 posts

Posted 10 May 2012 - 03:12 AM

Perfect - that did the trick.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users