On Friday, August 9, 2013 4:40:17 PM UTC-5, Jeremy Evans wrote:
>
> On Friday, August 9, 2013 1:39:01 PM UTC-7, Keith Moore wrote:
>>
>> I knew what I was attempting wasnt a very good idea. I just wasnt sure
>> what to do inside the apply_filter method, for example, where I set the
>> dataset = dataset.where...
>> Inside the dataset_module, would that just be self = self.where(.....)?
>>
>
> Well, self = self.where is a SyntaxError. You need to create a local
> variable. Extending my earlier example with your code:
>
> class Item < Sequel::Model(:ITEM)
> dataset_module do
> def apply_filter(params)
> filter_criteria = columns.map{ |c| c.to_s } & params.keys
> dataset = self
> filter_criteria.each do |attribute_name|
> attribute_value = "#{params[attribute_name].gsub('*','%')}%"
> dataset = dataset.where(Sequel.like(attribute_name.to_sym,
> attribute_value))
> end
> dataset.select_all
> end
> end
> end
>
> >> Ok, I understand now. I was able to get my previous code working with
> your suggestion. Thanks for your help.
>
>
> Note that your attribute_value will probably not work correctly for
> searches such as something* (gets translated to something%%, looking for a
> literal something%).
>
>> I see what your saying. I didn't think it was worth preventing that
since it does pass my tests with SQLite and works fine with Oracle. Do you
know of other databases that would complain about the extra %? Regardless,
thanks for pointing that out! I really appreciate it.
>
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.