On Thursday, March 29, 2012 12:23:06 AM UTC-7, entropy wrote: > > Hi everyone, > > I'm getting some strange behaviour and I've written a small test > script which shows exactly what I mean. > > I'm using ruby-1.9.2-p318 with sequel-3.30.0 and PostgreSQL-9.1.3 > > My code: > ------------------------------------- > require 'sequel' > > # DATABASE_URL => postgres://user:pass@localhost/db > DB = Sequel.connect( ENV['DATABASE_URL'] ) > > DB.create_table( :timestamp_test ) do > primary_key :id > timestamp :when, :null => false, :default => :now.sql_function > end > > class Test < Sequel::Model( DB[ :timestamp_test ] ) > end > > begin > test = Test.create() > puts "Update using the class" > Test.filter( :id => test.id ).update( :when => :now.sql_function ) > This works fine because this is Sequel::Dataset#update, which works with Sequel expressions.
> puts "\tSuccess!" > puts "Update using the instance" > test.update( :when => :now.sql_function ) > This fails because this is Sequel::Model#update, which attempts to typecast the expression. You can either turn off typecasting or not raise on typecasting failure to work around the issue. Alternatively, you could do test.this.update (which is Dataset#update for the model instance), or test.values.update (which is Hash#update) and then test.save. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/XeH8I0Ser1EJ. 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.
