# Boolean circles

**URL:** <https://www.ruby-forum.com/t/boolean-circles/131255>\
**Category:** Rails\
**Created:** [March 7, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/boolean-circles/131255 "2008-03-07T13:01:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@Fredrik\_K](https://www.ruby-forum.com/u/Fredrik_K)\
**Post date:** [March 7, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/boolean-circles/131255/1 "2008-03-07T13:01:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fredrik\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@Fredrik\_K](https://www.ruby-forum.com/u/Fredrik_K)\
**Post date:** [March 7, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/boolean-circles/131255/2 "2008-03-07T13:16:30Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Fredrik\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@Fredrik\_K](https://www.ruby-forum.com/u/Fredrik_K)\
**Post date:** [March 7, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/boolean-circles/131255/3 "2008-03-07T14:01:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fredrik\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@Fredrik\_K](https://www.ruby-forum.com/u/Fredrik_K)\
**Post date:** [March 7, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/boolean-circles/131255/4 "2008-03-07T15:22:26Z")

</div>

Hi,

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

/Fredrik

On Fri, Mar 7, 2008 at 2:00 PM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.”
