I have a model that will downcase a field before storing. The problem is
when attempting to filter using the value, it fails to return the result
unless it is already downcased. I have tried various hooks to no avail.
Is there any way for the final filter in the example below to work
without explicitly downcasing the string?
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite
class Foobar < Sequel::Model
set_schema do
primary_key :id
varchar :name, :unique => true, :null => false
end
def name=(n_name)
values[:name] = n_name.downcase
end
end
Foobar.create_table unless Foobar.table_exists?
a = Foobar.find_or_create(:name => 'Bob')
b = Foobar.filter(:name => 'bob').first
c = Foobar.filter(:name => 'Bob').first
puts a.nil? ? 'failed to create' : "Bob is: #{a.name} with ID: #{a.pk}"
puts b.nil? ? 'failed to find bob' : "bob is: #{b.name} with ID: #{b.pk}"
puts c.nil? ? 'failed to find Bob' : "Bob is: #{c.name} with ID: #{c.pk}"
Outputs:
Bob is: bob with ID: 1
bob is: bob with ID: 1
failed to find Bob
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---