Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This falls apart when you need multiple scopes as it can't tell how to group the 'AND' and 'OR's. The new Rails syntax avoids this problem.


That isn't a problem in Sequel, as you can pass a complex expression to #or, in which case it works as you would expect it to:

    Post.where(id: 1).or(Sequel.&({:id=>2}, {:name=>'Foo'}))
    # SELECT * FROM posts WHERE ((id = 1) OR ((id = 2) AND (name = 'Foo')))


Yay, Jeremy Evans spreading some Sequel knowledge ^_^

Big fan of Sequel; it's super sleek. As a side-note to Jeremy's comment, while (i guess) he used Sequel.& to demonstrate that OR and AND conditions can be combined freely, there are more succinct ways of expressing that particular query:

  # Using the a "virtual row" block:
  Post.where(id: 1).or{(id =~ 2) & (name =~ 'Foo')}

  # Or, if you don't fancy that kind of block magic, simply passing a Hash, 
  # the same way as with .where
  Post.where(id: 1).or(id: 2, name: 'Foo')




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: