Yii Framework Forum: relation with condition - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

relation with condition Rate Topic: -----

#1 User is offline   as_lh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 05-January 10

Posted 12 February 2010 - 09:20 AM

Hi,

i have those two tables that both have the attribute `languagecode` and also both have the attribute `description_id`.
Now i want to get the related entries using the relations attribute of one of their models.

so in "relations()" in model1 i added:
	
'descriptionType'	=> array(
	self::HAS_MANY, 
	'hotel_description_types', 
	'descriptiontype_id',
	'condition'=>'hotel_description_types.languagecode=:lang',
	'params' => array(':lang'=>'de'),
), ...


Now yii tells me:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'hotel_description_types.languagecode' in 'where clause'


... though it DOES exist in the Database! I tripple checked!

What could be the problem?
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 12 February 2010 - 09:55 AM

Use this condition instead, the table will get an alias that is the same as the relation name:

'condition'=>'descriptionType.languagecode=:lang',


0

#3 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 12 February 2010 - 09:57 AM

View Postas_lh, on 12 February 2010 - 09:20 AM, said:

Hi,

i have those two tables that both have the attribute `languagecode` and also both have the attribute `description_id`.
Now i want to get the related entries using the relations attribute of one of their models.

so in "relations()" in model1 i added:
	
'descriptionType'	=> array(
	self::HAS_MANY, 
	'hotel_description_types', 
	'descriptiontype_id',
	'condition'=>'hotel_description_types.languagecode=:lang',
	'params' => array(':lang'=>'de'),
), ...


Now yii tells me:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'hotel_description_types.languagecode' in 'where clause'


... though it DOES exist in the Database! I tripple checked!

What could be the problem?


Try
	
'descriptionType'	=> array(
	self::HAS_MANY, 
	'hotel_description_types', 
	'descriptiontype_id',
	'condition'=>'descriptionType.languagecode=:lang',
	'params' => array(':lang'=>'de'),
), ...


(not tested)
/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#4 User is offline   as_lh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 05-January 10

Posted 12 February 2010 - 10:15 AM

View Posttri, on 12 February 2010 - 09:57 AM, said:

Try
	
'descriptionType'	=> array(
	self::HAS_MANY, 
	'hotel_description_types', 
	'descriptiontype_id',
	'condition'=>'descriptionType.languagecode=:lang',
	'params' => array(':lang'=>'de'),
), ...


Didn't work either :(
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'descriptionType.languagecode' in 'where clause'

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users