How to cast field as type date (mysql)

35 views
Skip to first unread message

bill

unread,
Sep 1, 2014, 10:04:24 PM9/1/14
to redbe...@googlegroups.com
I am using the Readbean ORM. I am trying to import some emails into a mysql table using imap. The following code imports an array from imap. One of the fields is $reply_bean->date;

                    $imap_array=$this->retrieve_message($inbox, $email); 
                    $reply_bean = R::dispense('reply');
                    $reply_bean->setMeta("buildcommand.unique" , array(array('date')));
                    $reply_bean->date("Y-m-d H:i:s");
                    $reply_bean->import($imap_array);

                    
                    try {
                        $id = R::store($reply_bean); 
                    }    catch (Exception $exc) {
                        
                        echo ' DUPLICATE';
                       
                    }      
          
The problem I'm having is that I am having trouble casting the date field as type 'date' instead it remains varchar and is sorted in lexicographical order.

How can I fix this?

gabor

unread,
Sep 2, 2014, 2:27:24 PM9/2/14
to redbe...@googlegroups.com


You can't cast,
RedBeanPHP cannot change the column after it has been created, that would cause loss of data.

cheers
Gabor

bill

unread,
Sep 7, 2014, 10:59:51 AM9/7/14
to redbe...@googlegroups.com
Gabor,

Thanks for explaining this. I am using vession 3 , and reading on  http://redbeanphp.com/extra/meta_data  . It appears to say :"Since 3.0: Meta data can be used for explicit casts. For instance if you want to store something as a POINT datatype:"

Thank you,

Bill

gabor

unread,
Sep 8, 2014, 2:19:06 PM9/8/14
to redbe...@googlegroups.com

I recommend not to use that feature.
It has been created to cover certain edge cases only (forcing string formats for certain numerical formats etc).
Reply all
Reply to author
Forward
0 new messages