Advertisement
Guest User

Untitled

a guest
May 31st, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. validates_uniqueness_of :mobile
  2. validates_uniqueness_of :email
  3. validates_uniqueness_of :card_num
  4.  
  5. name mobile email card_num
  6. ============================================
  7. Mary 65666678 mary@gmail.com A001
  8.  
  9. name mobile email card_num
  10. ============================================
  11. Peter 65666678 peter@gmail.com A002
  12.  
  13. name mobile email card_num
  14. ============================================
  15. Peter 74009822 mary@gmail.com A002
  16.  
  17. name mobile email card_num
  18. ============================================
  19. Peter 65666678 mary@gmail.com A001
  20.  
  21. User.select("CASE
  22. WHEN (name = 'Peter') THEN 'name'
  23. WHEN (mobile = '74009822') THEN 'mobile'
  24. WHEN (email = 'mary@gmail.com') THEN 'email'
  25. ELSE 'card_num'
  26. END as col_name").where("name = 'Peter' or mobile = '74009822' or email = 'mary@gmail.com' or card_num='A002'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement