Boolean circles..

Fredrik Karlsson
Fri, 07 Mar 2008 12:00:31 -0000

Hi,

This is just kindof a RoR question, but since you all potentially do
the same things as I do, I thought I''ll ask here..

Im trying to use the boolean type in the database. Migrations is no
problem, it even converts the 0/1 values from my import CSV to false
and true.
However, I cannot make the :conditions part of a find work:

Loading development environment (Rails 2.0.2)
>> c = Club.find(1)
=> #<Club id: 1, club_name: "Ume\214 Kuniba kai", logo: nil,
currently_active: 1, created_at: "2008-03-07 12:52:35", updated_at:
"2008-03-07 12:52:35">
>> m = c.members.find(:first, :conditions => "is_active = 1")
=> nil
>> m = c.members.find(:first, :conditions => "is_active =
true")
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
true: SELECT * FROM members   WHERE (members.club_id = 1 AND
(is_active = true))  LIMIT 1
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in
`log''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in
`execute''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:345:in
`catch_schema_changes''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in
`execute''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:256:in
`select''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all_without_query_cache''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:55:in
`select_all''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:532:in
`find_by_sql''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1233:in
`find_every''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1227:in
`find_initial''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:502:in
`find''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_many_association.rb:66:in
`find''
	from (irb):3
>> m = c.members.find(:first, :conditions => "is_active =
false")
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
false: SELECT * FROM members   WHERE (members.club_id = 1 AND
(is_active = false))  LIMIT 1
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in
`log''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in
`execute''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:345:in
`catch_schema_changes''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in
`execute''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter.rb:256:in
`select''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all_without_query_cache''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:55:in
`select_all''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:532:in
`find_by_sql''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1233:in
`find_every''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1227:in
`find_initial''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:502:in
`find''
	from
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/has_many_association.rb:66:in
`find''
	from (irb):4
>> m = c.members.find(:first, :conditions => "is_active = 0")
=> nil

If I change the column to an integer, everything works, except of
course the .toggle-method which does not know how to handle an integer
value.

What do I do? As you can see, I am using sqlite3

/Fredrik
--
"Give up learning, and put an end to your troubles."