Booleans and SQLite

6 views
Skip to first unread message

henq

unread,
Oct 6, 2015, 6:11:32 AM10/6/15
to Rose::DB::Object
Hi,
I have an SQLite table 'users' with a column like
    email_validated BOOLEAN NOT NULL DEFAULT 0

(I know SQLite does not support boolean natively, but I like to use the create table definitions for other db's too).

When I do this
  my $u = MyIMDB::Models::User->new(user_name => $user_name);
  $u->load;
  $u->{email_validated} = 1;
  $u->save;

The column email_validated is not updated to 1. 

I tried by adding a column type definition like
  __PACKAGE__->meta->setup (
    table      => 'users',
    unique_key => ['user_name', 'id'],
    columns =>
    [
      email_validated => { type => 'boolean' },
    ],
    auto       => 1,

Funny thing is that when I do 
   my $u = MyIMDB::Models::User->new;
   $u->{email_validated} = 1;
   $u->save;
(so no load of existing row), the column email_validated is set to 1...


Why does the ->save fails to set the boolean column?




~h

John Siracusa

unread,
Oct 6, 2015, 9:19:43 AM10/6/15
to rose-db-object
You shouldn't directly access hash keys in objects. Call object methods instead (e.g., $u->email_validated(1)). This may or may not solve your problem, but it's a start.

-John

--
Source: https://github.com/siracusa/rose
CPAN: http://search.cpan.org/dist/Rose-DB-Object
---
You received this message because you are subscribed to the Google Groups "Rose::DB::Object" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rose-db-objec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

henq

unread,
Oct 6, 2015, 4:49:43 PM10/6/15
to Rose::DB::Object
*facepalm does
John, thanx, that was it. 
Reply all
Reply to author
Forward
0 new messages