PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 12, 2022

[FIXED] Yii2 : Active Record add Not In condition

 January 12, 2022     activerecord, yii, yii2     No comments   

Issue

What is the active Record way of adding IN condition to an active Query in yii 1.x you could use CDbCriteria like this

$cr = new CDbCriteria();
$cr->addNotInCondition('attribute', $array);

There seem to be no equivalent API call in yii2 active record implementation, how to do this via active record ?


Solution

Well all query operands seems now merged within in yii\db\QueryInterface::Where() per documentation an In condition can now be added using something like

$query = MyModel::find()->where(['attribute'=>$array]);

for a not In condition it is slightly different format

$query = MyModel::find()->where(['not in','attribute',$array]);


Answered By - Manquer
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing