Rails Model find where not equal

前端 未结 6 1386
孤街浪徒
孤街浪徒 2020-12-07 14:29

How can I find records in my database on a not equal condition? I have this now, but is there a fancy rails-speak way of doing it?

GroupUser.where(\'user_id         


        
6条回答
  •  广开言路
    2020-12-07 14:53

    The only way you can get it fancier is with MetaWhere.

    MetaWhere has a newer cousin which is called Squeel which allows code like this:

    GroupUser.where{user_id != me}
    

    It goes without saying, that if this is the only refactor you are going to make, it is not worth using a gem and I would just stick with what you got. Squeel is useful in situations where you have many complex queries interacting with Ruby code.

提交回复
热议问题