On Sep 23, 11:32 am, Kendall Gifford <[email protected]> wrote:
> Hello everyone.
>
> I'm really new to Sequel and am writing a script that accesses one of
> our existing (old) MySQL databases (server running 4.1.12). I've got
> ruby 1.8.7 (patchlevel 302) and the sequel gem (version 3.15.0)
> installed on my dev machine from which I'm accessing my server.
>
> The problem I'm having is getting the boolean_readers plugin to work.
> I don't know if it is just because I'm so new to Sequel and don't know
> the proper method or if there is some other problem.
>
> I have a table in my database named "tblEmployees" with a field names
> "Active" that is a TINYINT(1) field (signed). I'd like to be able to
> read this field using: x.Active? and access the numeric value with
> x.Active. From my reading thus far, it appears that the solution is to
> turn "convert_tinyint_to_bool" off (done) and enable the
> "boolean_readers" plugin on this model. Disabling tinyint to boolean
> conversion works great but I don't get any "?" attribute reader
> methods for my tinyint field:
>
> $ irb (some output omitted for brevity)> require 'rubygems'
> > require 'sequel'
> > DB = Sequel.connect("mysql2://user:p...@server/db")
> > Sequel::MySQL.convert_tinyint_to_bool = false
> > Sequel::Model.plugin :boolean_readers

You probably want:

  Sequel::Model.plugin(:boolean_readers){|c| db_schema[c][:db_type]
=~ /\Atinyint/}

If you turn convert_tinyint_to_bool = false, then the :type will
be :integer, so the boolean_readers plugin will not consider the
column as a boolean.  You need to use the block to configure it to do
so.  This example is included in the documentation:
http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/BooleanReaders.html

Jeremy

-- 
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.

Reply via email to