E
E
EVOSandru62015-02-12 07:47:18
Yii
EVOSandru6, 2015-02-12 07:47:18

How to add a condition in Cdbcriteria in Yii?

Good afternoon, there are 3 tables:
t_service (CODE, NAME)
mc_faq (NAME, DESCRIPTION, EXIST)
l_service_22_faq (CODE, CODE_1, CODE_2) - linking
stackoverflow.com/questions/8044552/searching-in-y...
Used this recipe to find all the faqs for this service, there is such a moment:
At the deletion stage for mc_faq, I do EXIST = '2' - this is a complete deletion (0 - deletion)
I want to add a condition for $criteria, so that only those FAQs with EXIST are pulled out in the grid! = 2
Tried like this;

$criteria = new CDbCriteria();
$criteria->with = array(
    'faq_service' => array(
        'condition' => 'CODE_1 = '.$model->CODE,
        'group'     => 'CODE_2',
        'together'=>true
    ),
);
$criteria->condition = 'mc_faq.EXIST = 1';

But I got an error:
CDbCommand failed to execute the SQL query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'mc_faq.EXIST' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`CODE`) FROM `mc_faq` `t` LEFT OUTER JOIN `l_service_22_faq` `faq_service` ON (`faq_service`.`CODE_2`=`t`.`CODE `) WHERE (mc_faq.EXIST = 1) AND (CODE_1 = 25)
Relationships in the Service model :
'faq'=>array(self::MANY_MANY, 'Faq',  'l_service_22_faq(CODE_1, CODE_2)'),
'service_faq'=>array(self::HAS_MANY, 'LService22Faq', 'CODE_1'),

Relationships in the LService22Faq model :
'service'  => array( self::BELONGS_TO, 'Service', 'CODE_1' ),
'faq'   => array( self::BELONGS_TO, 'Faq', 'CODE_2' ),

Help advice good people!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-02-13
@EVOSandru6

FROM `mc_faq` `t`
See here the alias for the default table. Try like this
$criteria->condition = 't.EXIST = 1';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question