Hello everyone!

I'm learning how Sequel and Ruby work and I wrote this small script which 
puzzles me.

The logic is:

1. I create an in-memory database
2. I create a table with a boolean field in it
3. I declare a model of that table
4. I use the model to populate the table
5. I try to use .where selector with a boolean field name -- BUT this 
doesn't work!

The Service.where(:hb_eligible).count returns there, but in fact there are 
two records in the table that satisfy the criteria.

The introspection shows [:hb_eligible, {:allow_null=>true, :default=>nil, 
:primary_key=>false, :db_type=>"boolean", :type=>:boolean, 
:ruby_default=>nil}].

When I do Service.where(:hb_eligible).sql in irb it returns
=> "SELECT * FROM `services` WHERE `hb_eligible`"
which in my limited understanding of SQL is what I want.

Help?!

Ollie

PS ruby 1.9.3p125 (2012-02-16) [i386-mingw32], sequel 3.34.1

# dbtest.rb

require "rubygems"
require "bundler/setup"
require "sequel"

DB = Sequel.sqlite

DB.create_table :services do
  primary_key :id
  text :shortcode
  text :description
  boolean :hb_eligible
end

class Service < Sequel::Model
end

[
  {shortcode: "window_cleaning", description: "Communal Window Cleaning", 
hb_eligible: true},
  {shortcode: "grounds_maintenance", description: "Grounds Maintenance", 
hb_eligible: true},
  {shortcode: "heating", description: "Heating & Hot Water", hb_eligible: 
false},
  {shortcode: "tv_licence", description: "TV Licence", hb_eligible: false}
].each { |r| Service.create(r) }

puts "dbtest.rb loaded"

puts "Service.count = #{Service.count}, of which HB eligible = 
#{Service.where(:hb_eligible).count}"

puts "#{DB.schema(:services)}"

# end of dbtest.rb

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