Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Enums with Y/N values
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Eugene Janusov  
View profile   Translate to Translated (View Original)
 More options 9 Oct, 01:51
From: Eugene Janusov <esy...@gmail.com>
Date: Thu, 8 Oct 2009 17:51:44 -0700 (PDT)
Local: Fri 9 Oct 2009 01:51
Subject: Enums with Y/N values
Hi,

I'm using symfony, but I suppose my problem is related only to
Doctrine.

In my schema I have lots of fields like this:

    is_public as isPublic:
      type: enum
      values: [Y, N]
      default: 'N'
      notnull: true

By some reason I cannot use boolean type instead of binary enum.

When I generate model classes (`symfony doctrine:build-model`), such
fields magically transform into the following PHP code:

        $this->hasColumn('is_public as isPublic', 'enum', null, array(
             'type' => 'enum',
             'values' =>
             array(
              0 => true,
              1 => false,
             ),
             'default' => 'N',
             'notnull' => true,
             ));

Y/N values have been intelligently replaced with true/false.
Unfortunately, I need precisely string Y/N values.
But more critical issue is that the default value was left unchanged.
Thus, when I try to create tables (`symfony doctrine:build-db` or
`:rebuild-db`), I expectedly receive a complain that 'N' is invalid
value.

Moreover, if I build SQL schema (`symfony doctrine:build-sql`), I get
the following result:

    is_public ENUM('1', '') DEFAULT 'N' NOT NULL,

because PHP converts FALSE to an empty string, not a zero.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Wage  
View profile   Translate to Translated (View Original)
 More options 9 Oct, 02:53
From: Jonathan Wage <jonw...@gmail.com>
Date: Thu, 8 Oct 2009 20:53:52 -0500
Local: Fri 9 Oct 2009 02:53
Subject: Re: [doctrine-dev] Enums with Y/N values

It is because you have the N in single quotes.

   is_public as isPublic:
     type: enum
     values: ['Y', 'N']
     default: 'N'
     notnull: true

In the yaml parser, just Y or N will be parsed in to PHP true or false. If
you want the actual value to be a string Y and string N then you need to
make sure to wrap it in single quotes.

You could also do this.

   is_public as isPublic:
     type: enum
     values: [Y, N]
     default: N
     notnull: true

That would be all boolean, but that would just be this.

   is_public as isPublic:
     type: boolean
     default: false

Which is what I would recommend to use.

- Jon

--
Jonathan H. Wage (+1 415 992 5468)
Open Source Software Developer & Evangelist
sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org

You can contact Jonathan about Doctrine, Symfony and Open-Source or for
training, consulting, application development, or business related questions
at jonathan.w...@sensio.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Janusov  
View profile   Translate to Translated (View Original)
 More options 12 Oct, 15:09
From: Eugene Janusov <esy...@gmail.com>
Date: Tue, 13 Oct 2009 01:09:14 +1100
Local: Mon 12 Oct 2009 15:09
Subject: Re: [doctrine-dev] Re: Enums with Y/N values
values: ['Y', 'N'] works as I need, thanks.

Huh, I was absolutely sure that I already tried this variant and it
didn't help...

type: boolean of course is obvious choice in this case, but as I said
for some reason beyond me I can't use it.

On 9.10.09 12:53, Jonathan Wage wrote:

--
Best regards,
Eugene Janusov.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google