Yii Framework Forum: Related Many Many Sql Error - Yii Framework Forum

Jump to content

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

Related Many Many Sql Error Rate Topic: -----

#1 User is offline   kuxyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 09-March 13

Posted 02 April 2013 - 09:58 PM

Getting this error from giix generated crud:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'contacts_contacts. contact_id' in 'on clause'. The SQL statement executed was: SELECT `contacts`.`id` AS `t1_c0`, `contacts`.`firstname` AS `t1_c1`, `contacts`.`lastname` AS `t1_c2`, `contacts`.`salutation` AS `t1_c3`, `contacts`.`title` AS `t1_c4`, `contacts`.`notes` AS `t1_c5`, `contacts`.`telephone` AS `t1_c6`, `contacts`.`mobile` AS `t1_c7`, `contacts`.`switchboard` AS `t1_c8`, `contacts`.`fax` AS `t1_c9`, `contacts`.`address1` AS `t1_c10`, `contacts`.`address2` AS `t1_c11`, `contacts`.`address3` AS `t1_c12`, `contacts`.`address4` AS `t1_c13`, `contacts`.`address5` AS `t1_c14`, `contacts`.`postcode` AS `t1_c15`, `contacts`.`region` AS `t1_c16`, `contacts`.`user_id` AS `t1_c17`, `contacts`.`company_id` AS `t1_c18`, `contacts`.`create_time` AS `t1_c19`, `contacts`.`create_user_id` AS `t1_c20`, `contacts`.`update_time` AS `t1_c21`, `contacts`.`update_user_id` AS `t1_c22` FROM `tbl_contact` `contacts` INNER JOIN `tbl_attribute_assignment` `contacts_contacts` ON (`contacts_contacts`.` contact_id`=:ypl0) AND (`contacts`.`id`=`contacts_contacts`.`attribute_id `). Bound with :ypl0='2'


The relationship code:
	public function relations() {
		return array(
			...
			'attributes' => array(self::MANY_MANY, 'Attribute', 'tbl_attribute_assignment( attribute_id, contact_id )'),
		);
	}


and the view:

	foreach($model->attributes as $relatedModel) {
		echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('attribute/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
	}



What am i doing wrong?
0

#2 User is offline   kuxyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 09-March 13

Posted 03 April 2013 - 01:09 AM

Should I not be using Gii to generate code for many_many relationships? Tried some of the other templates (Awecrud) and they failed with errors too.
0

#3 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 07 April 2013 - 08:22 PM

There's a space here:

`contacts_contacts`.` contact_id`


And the cause is at:

'attributes' => array(self::MANY_MANY, 'Attribute', 'tbl_attribute_assignment( attribute_id, contact_id )')


Remove the spaces and let me know whether it works:

'attributes' => array(self::MANY_MANY, 'Attribute', 'tbl_attribute_assignment(attribute_id,contact_id)'),


Was the code generated like this or did you (or your IDE) add those spaces?
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