⚠ 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

Adding "where" function for a related table?



rostamiani

rostamiani
  • profile picture
  • Member

Posted 26 May 2016 - 05:57 AM

Hi

 

I need to add a condition for a related table, not the main table.

This is my code:

$crud->set_table('Requests')
	->set_subject('درخواست رزومه')

	->columns('Resume_id','Users_id','Status')
	->fields('Resume_id','Users_id','Status')
	->required_fields('Resume_id','Users_id')

	->set_relation('Users_id','Users','UserName')

	->where('Users.Type = 2')

Now I have this error:

Error Number: 1054

Unknown column 'Users.Type' in 'where clause'

SELECT `Requests`.*, jc474b407.UserName AS sc474b407 FROM (`Requests`) LEFT JOIN `Users` as jc474b407 ON `jc474b407`.`id` = `Requests`.`Users_id` WHERE  `Users`.`Type` = 2 ORDER BY `Requests`.`id` desc LIMIT 100

Filename: E:\Users\MohammadMahdi\Documents\Projects\Khayyamkar\system\database\DB_driver.php

Line Number: 330

 

 

And the problem is that the name of related table is 'jc474b407' and not Users anymore!

How can I add this WHERE to the query?

 

Thanks


titu

titu
  • profile picture
  • Member

Posted 27 May 2016 - 14:50 PM

Try this:

 

->set_relation('Users_id','Users','UserName',array('Type'=>2));