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

Note that your attribute_value will probably not work correctly for 
searches such as something* (gets translated to something%%, looking for a 
literal something%).

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.


Reply via email to