> > janko-m <https://github.com/janko-m> commented > > If we had a joined dataset where we wanted to filter by many columns on > the other table, currently we could explicitly qualify each column using > Sequel[]: > > Track > .association_join(:album) > .where( > Sequel[:albums][:released_at] => Date.today, > Sequel[:albums][:name] => "Back to Black", > Sequel[:albums][:single] => true, > ) > > or virtual rows: > > Track > .association_join(:album) > .where{ > (albums[:released_at] =~ Date.today) & > (albums[:name] =~ "Back to Black") & > (albums[:single] =~ true) > } > > Since that can get a bit repetitive if we have a lot of column filters, > and we might want to keep using hashes, we can rewrite it using > Sequel.deep_qualify: > > Track > .association_join(:album) > .where(Sequel.deep_qualify(:albums, > released_at: Date.today, > name: "Back to Black", > single: true, > )) > > This pull request adds a syntax sugar for the latter Sequel.deep_qualify > version, > allowing us to use a nested hash instead, where the key is the table name > and the value is the expression we want to deep qualify (like in Active > Record): > > Track > .association_join(:album) > .where(albums: { > released_at: Date.today, > name: "Back to Black", > single: true, > }) > > I think it would be a very convenient syntax to have, I found myself > wishing to use it. Let me know if you're open to accepting this feature. In > that case I'll go ahead and update the documentation. >
> jeremyevans <https://github.com/jeremyevans> commented > > Sorry, but this can't be supported, as the syntax already means something > else (assume column a is boolean and b is integer): > > DB[:table].where(:a=>{:b=>1})# SELECT * FROM table WHERE (a = (b = 1)) > > This is something that could be supported via an extension using a > different method. Example: > > Track > .association_join(:album) > .qualified_where(album: { > released_at: Date.today, > name: "Back to Black", > single: true, > }) > > I'm not sure whether I'd like to ship such an extension with Sequel or > not. I'd like to get feedback from the community before making a decision, > so please bring it up on the Google Group if you would like to see it added. > So, I'd like to use any handy method for this task, which is common when working with joins. I also didn't find such example: Sequel[:albums][ released_at: Date.today, name: "Back to Black", single: true ] And it converts in SQL, like: "albums".(("released_at" = ...) AND (...)) But I'm not sure that this is valid SQL. -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
