Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. ALTER TABLE `foo`
  2. ADD UNIQUE KEY `foo_uk` (`field1`, `field2`);
  3.  
  4. public function rules()
  5. {
  6. return array(
  7. ...
  8. array('field1', 'unique', 'criteria'=>array(
  9. 'condition'=>'`field2`=:field2',
  10. 'params'=>array(
  11. ':field2'=>$this->field2
  12. )
  13. ),
  14. ...
  15. );
  16. }
  17.  
  18. SELECT 1 FROM `foo` `t` WHERE (`field2`=:field2) AND (`t`.`field1`=:ycp0) LIMIT 1
  19.  
  20. CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity
  21. constraint violation: 1062 Duplicate entry 'field1TestData-field2TestData' for
  22. key 'foo_uk'. The SQL statement executed was: INSERT INTO `foo` (`field1`,
  23. `field2`...etc) VALUES (:yp0, :yp1...etc)
  24.  
  25. public function rules() {
  26. return array(
  27. array('firstKey', 'UniqueAttributesValidator', 'with'=>'secondKey'),
  28. );
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement