We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42082
    • 72 Posts
    Hey y'all,
    Just wondering If there is a way to put boolean tables into the schema. Would I do something like this?
    <field key="show_date" dbtype="int" precision="2" phptype="boolean" null="false" default=""/>
    

    or maybe this?
    <field key="show_desc" dbtype="boolean" precision="2" phptype="integer" null="false" default=""/>
    

    I not even sure what the difference is between phptype and dbtype.
    Thanks y'all any information on this will be very helpful.

    ModxNooby
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      dbtype is the database (MySQL? SQL Server?) data type, phptype is PHP's data type for the same data. They frequently aren't the same, and you can get some unexpected PHP output from not-quite-compatible data types. It's possible in PHP to use typecasting, but it's much better to tell xPDO what PHP data type you want and let MODx take care of any typecasting or conversion necessary.

      As an example, using 0 as a boolean false in PHP can cause some hard-to-locate bugs, since 0 may be a perfectly good value, such as the (virtual) ID #0 the Tree root for a Wayfinder snippet call, or how many children a given resource has.

      In MySQL, the 'boolean' type is an alias for TINYINT(1) and 0 is False while any non-0 value is True.
      http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

      Some interesting things to know when using PHP booleans in the comments here.
      http://www.php.net/manual/en/language.types.boolean.php
      [ed. note: sottwell last edited this post 12 years, 9 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 42082
        • 72 Posts
        Oh okay, So would the field for the schema I'm doing look something like this?
        <field key="show_author" dbtype="tinyint" precision="1" phptype="integer" null="false" default=""/>
        

        And If so, how would the mysql and xpdo know that the tables are for boolean values?

        Thanks for clearing up the differences between phptype and dbtype.

        Modxnooby
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The phptype would be boolean; the dbtype can also be boolean but it would internally (by MySQL, anyway, I don't know about MS SQL or any others) tinyint(1). Personally, since I'm thinking of it as a boolean I'd use boolean.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 42082
            • 72 Posts
            Thanks so Much sottwell!
            This has really helped me a ton so thank you again.So just to make sure I got ths and i wont mess anything up is this xml/xpdo field good to go??
            <field key="show_author" dbtype="boolean" precision="1" phptype="boolean" null="false" default=""/>
            

            Thanks so much ^-^
            modxnooby
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Well, that's how I would do it. Not sure about the precision, though, since internally MySQL is already thinking that from its interpretation of the boolean type, but I don't know a) if it's possible to leave it empty here, or b) if it's going to hurt anything by being there - I would presume that it won't hurt anything.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 3749
                • 24,544 Posts
                The modUser 'active' class is a boolean. It looks like this in the mysql schema:

                <field key="active" dbtype="tinyint" precision="1" phptype="boolean" attributes="unsigned" null="false" default="1" />
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I like to be contrary wink
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 3749
                    • 24,544 Posts
                    I doubt if it really matters. I was just curious what one actually looked like. wink
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 42082
                      • 72 Posts
                      Thank you guys so much! I will use the sample that Bob showed us just because I want to make sure that I wont mess anything up smiley. I am very thankful to you both as you have taught me a ton. Thanks guys ^-^

                      Modxnooby