Boolean circles

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:inexecute’
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:inexecute’
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:inselect_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:infind_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:infind_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:infind’
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:inexecute’
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:inexecute’
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:inselect_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:infind_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:infind_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:infind’
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.”

On Mar 7, 2008, at 7:00 AM, Fredrik K. wrote:

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

Have you tried:
:conditions => [‘is_active = ?’, true]

and let the adapter deal with how to represent booleans for the column?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

On 7 Mar 2008, at 12:00, Fredrik K. wrote:

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”)

How about c.members.find(:first, :conditions => [“is_active = ?”, true])

Fred.

Hi,

You guys are sooo good. Of course that worked. Thanks!

/Fredrik

On Fri, Mar 7, 2008 at 2:00 PM, Frederick C.
[email protected] wrote:

Im trying to use the boolean type in the database. Migrations is no
=> nil
true: SELECT * FROM members WHERE (members.club_id = 1 AND
from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/
select_all' active_record/base.rb:502:in active_record/connection_adapters/abstract_adapter.rb:150:in from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/ find_by_sql’
active_record/associations/has_many_association.rb:66:in


“Give up learning, and put an end to your troubles.”