0

I have table called user_rights. It contains following fields

rights_id, user_rule_id, user_p_id, user_group_id and region_id

How can I get row which rights_id=15, user_rule_id=4, user_p_id=2, user_group_id=6 and region_id=100? How can I check whether such row exists or not?

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
phpdev
  • 511
  • 4
  • 22
  • what have you **tried yourself** so far? – Franz Gleichmann Jan 20 '17 at 12:21
  • $valueExists=UserRights::model()->exists('user_rule_id=:user_rule_id and user_p_id=:user_p_id and user_group_id=:user_group_id', array(":user_rule_id"=>4, ":user_p_id"=>1, ":user_group_id"=> $getallowedGroup )); – phpdev Jan 20 '17 at 12:27

1 Answers1

2

Assuming you have a model name UserRights based on table user_rights you could use findAllByAttributes

$queryArray['rights_id'] = 15; 
$queryArray['user_rule_id'] = 4;     
$queryArray['user_p_id'] = 2; 
$queryArray['user_group_id'] = 6; 
$queryArray['region_id'] = 100; 

$modelUsers= UserRights::model()->findAllByAttributes($queryArray);

in $modelUsers you obtain an array with all the models you need .. if the lenght of the array is 0 then nn model

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • You should use `findByAttributes` as this will return only one model. This is useful if may records match the attributes. – topher Jan 20 '17 at 12:49