# Mysql boolean field

**URL:** <https://www.ruby-forum.com/t/mysql-boolean-field/118615>\
**Category:** Rails\
**Created:** [October 29, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615 "2007-10-29T14:33:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyzt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/839c29/32.png) [@xyzt](https://www.ruby-forum.com/u/xyzt)\
**Post date:** [October 29, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615/1 "2007-10-29T14:33:24Z")

</div>

hello,  
I have a boolean field(is\_suit) in a table(I use mysql) and I have Room  
class for this table.I compare the room entity lie this:

\<%if room.is\_suit? then%\>  
\<%=image\_tag(’/images/icon/suit.jpg’) %\>  
\<%end%\>

but it shows the image for all the records not just for is\_suit=b’1’ but  
also is\_suit=b’0’.  
where’s the wrong?

thanks.

---

<div class="post-metadata">

**Author:** ![xyzt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/839c29/32.png) [@xyzt](https://www.ruby-forum.com/u/xyzt)\
**Post date:** [October 29, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615/2 "2007-10-29T14:35:03Z")

</div>

Hi,

BahadÄ±r DoÄŸan wrote:

> I have a boolean field(is\_suit) in a table(I use mysql) and I have Room  
> class for this table.

Could you post the migration that generated this field and the DDL  
(“explain rooms”) that resulted from it?

Lutz

---

<div class="post-metadata">

**Author:** ![xyzt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/839c29/32.png) [@xyzt](https://www.ruby-forum.com/u/xyzt)\
**Post date:** [October 29, 2007, 2:37pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615/3 "2007-10-29T14:37:40Z")

</div>

Lutz H. wrote:

> Hi,
> 
> BahadÄ±r DoÄŸan wrote:
> 
> > I have a boolean field(is\_suit) in a table(I use mysql) and I have Room  
> > class for this table.
> 
> Could you post the migration that generated this field and the DDL  
> (“explain rooms”) that resulted from it?
> 
> Lutz

CREATE TABLE `msf`.`rooms` (  
`id` int(10) unsigned NOT NULL auto\_increment,  
`odano` int(10) unsigned NOT NULL,  
`tekyatak` int(10) unsigned NOT NULL,  
`ciftyatak` int(10) unsigned NOT NULL,  
`kat` int(10) unsigned NOT NULL,  
`is_suit` bit(1) NOT NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB AUTO\_INCREMENT=5 DEFAULT CHARSET=latin1;

---

<div class="post-metadata">

**Author:** ![xyzt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/839c29/32.png) [@xyzt](https://www.ruby-forum.com/u/xyzt)\
**Post date:** [October 29, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615/4 "2007-10-29T14:54:28Z")

</div>

Him

BahadÄ±r DoÄŸan wrote:

> `is_suit` bit(1) NOT NULL,

The possible values of this field are b’1’ and b’0’ for true and false.  
On the RoR site, these are represented as “\001” and “\000” which are  
_both true_.

If you generate a boolean field using a migration

t.column :is\_suit, :boolean

a column with the MySQL type tinyint(1) is created. For this column,  
is\_suit? works.

Lutz

---

<div class="post-metadata">

**Author:** ![xyzt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/839c29/32.png) [@xyzt](https://www.ruby-forum.com/u/xyzt)\
**Post date:** [October 29, 2007, 3:05pm UTC](https://www.ruby-forum.com/t/mysql-boolean-field/118615/5 "2007-10-29T15:05:50Z")

</div>

thanks.that solved the problem.
