On Friday, November 8, 2013 9:31:17 AM UTC-8, Phrogz wrote: > *(I originally posted this question > <http://stackoverflow.com/q/19864665/405017> on Stack Overflow. Please feel > free to answer there, too, if you want SO rep.)* > > Given a dataset that has multiple filters applied, how can I create a new > dataset that removes or overrides one of the existing filters? > > ds1 = DB[:x].filter(a:1, b:2)#=> <Sequel::Dataset: "SELECT * FROM x WHERE ((a > = 1) AND (b = 2))"> > > ds2 = ds1.filter(a:42) # I want to CHANGE a, not add another#=> > <Sequel::Dataset: "SELECT * FROM x WHERE ((a = 1) AND (b = 2) AND (a = 42))"> > > The #unfiltered method removes all filters (e.g. it removes b=2). While > that would be easy to re-add in the above simple case, it would result in > code duplication in my real case. > > So, is this possible? > Yes, it is possible. However, the need for what you are describing is virtually always is due to a design problem. If you might need different values later, use a prepared statement or a delayed evaluation. It's much better to change the design in such cases.
If you absolutely can't change the design, the most robust way to fix this is to write an ASTTransformer that will parse the current expression tree and return a new expression tree with the value changed. Even with that, I don't think the problem is solvable in the general sense. I remember someone doing something similar by manually parsing the expression tree, which worked in simple cases. However, I can't find a link to the related code. Thanks, Jeremy -- 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 http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/groups/opt_out.
