No replies?   I guess I'm imagining things then and this isn't
supported by cake?

To help make this topic a better reference source should future people
have a question on this, use the following code in your model:


                function getMyEnum()
                {
                        $rows=$this->query("SHOW COLUMNS FROM myTable LIKE
'myEnumColumnName'");
                        foreach ($rows[0][0] as $key => $value)
                        {
                                if ($key=='Type')
                                {
                                 preg_match_all("/'(.*?)'/", $value, $matches);
                                 $arryEnum= $matches[1];
                                }
                        }
                        return $arryEnum;
                }

(Obviously, replacing getMyEnum, myTable and myEnumColumn with whatever
your situation dictates.

And then in the controller, add:

                        $this->set('Myvar',$this->MyModel->getMyEnum());


This could be abstracted further by passing the table name and column
name to the function, but then, maybe such functionality might make a
good addition to the cake model?

However, the lesson I've learned from this is that you still require a
separate db query to load the enum array.  In that case, maybe it would
just be better to store enum values in a separate table with their own
model.  I don't know what kind of performance difference there may be
between the two approaches. But in general, I avoid enum because
changing the values involves an ALTER TABLE and the sql is
non-portable.  But there are cases where it is useful, and retrieving
selected values doesn't involve a join.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to