Yii Framework Forum: [Resolvido] Criteria Join - Yii Framework Forum

Jump to content

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

[Resolvido] Criteria Join Rate Topic: -----

#1 User is offline   bmsrox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 03-August 11

Posted 15 February 2014 - 07:20 PM

Eai pessoal podem me ajudar com essa ??

A query abaixo esta apresentando esta mensagem

O active record "Products" está tentando selecionar uma coluna inválida "c.category". Note, a coluna deve existir na tabela ou ser uma expressão de alias (apelido)

Se eu monto a query no sem criteria ele funciona.

$criteria=new CDbCriteria;
$criteria->select = array('t.id', 't.title','c.category');
$criteria->condition = 't.status = 1';
$criteria->join  = 'INNER JOIN tbl_category_products cp ON cp.id_products = t.id AND cp.id_category = :idCat ';
$criteria->join .= 'INNER JOIN tbl_category c ON c.id = cp.id_category';
$criteria->with = array('images'=>array('condition'=>'image_showcase = 1'));
$criteria->order = 't.order ASC';
$criteria->params = array(':idCat'=>$id);

0

#2 User is offline   bmsrox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 03-August 11

Posted 16 February 2014 - 10:17 AM

Depois te fritar o cérebro, eu achei uma solução

Segue exemplo

$sql = "SELECT t.id, t.title, c.category, i.image_small
		FROM tbl_products t
		INNER JOIN tbl_category_products cp ON cp.id_products = t.id AND cp.id_category = :idCat
		INNER JOIN tbl_category c ON c.id = cp.id_category
		LEFT OUTER JOIN tbl_images i ON (i.id_products = t.id AND i.image_showcase = 1)
		WHERE t.status = 1
		ORDER BY t.order ASC";

		$dataProvider = new CSqlDataProvider($sql, array('params'=>array(
                   ':idCat'=>$id,
            )));
		$dataProvider->getData();

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