Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Enumerations with scaffolding, migrations, and ORM
  • Hi guys, I'm planning to use an enumeration for one of the fields in my database. Is there any way to pull the available enumeration values with ORM? I'm not seeing any way to use DBUtil to create a table and set the values for an enumeration, so I'm guessing I'll have to do the query by hand inside of the migration? Is there a way to set the values via scaffolding? It's possible I'll end up using a many-to-many relationship for the table instead, depending on the answer I receive. Assuming I can't, how can I use scaffolding to generate a model with a many-to-many relationship? Is this also not possible?
  • Not sure if this will help you, but I use this to get enum values to populate a select box.
    /**
     * Fetches the enum values from a table and returns an array suitable for
     * use with Form::select.
     *
     * @param    string    table name
     * @param    string    enum field name
     * @param    array     array of values to exclude from the returned array
     *
     * @return   array in the form array('option1'=>'option1', 'option1'=>'option1' etc... )
     */
    public static function get_enum_values($table, $field, $exclusions = array())
    {
     $column = DB::list_columns($table, $field);
     $options = array_values($column[$field]['options']);
     $options = array_diff($options, $exclusions);
     return array_combine($options, $options);
    }
    
  • Paul Boco wrote on Sunday 29th of May 2011:
    Not sure if this will help you, but I use this.
    /**
     * Fetches the enum values from a table and returns an array suitable for
     * use with Form::select.
     *
     * @param    string    table name
     * @param    string    enum field name
     * @param    array     array of values to exclude from the returned array
     *
     * @return   array in the form array('option1'=>'option1', 'option1'=>'option1' etc... )
     */
    public static function get_enum_values($table, $field, $exclusions = array())
    {
     $column = DB::list_columns($table, $field);
     $options = array_values($column[$field]['options']);
     $options = array_diff($options, $exclusions);
     return array_combine($options, $options);
    }
    

    Thanks! Now I just need to know how to use scaffolding for many-to-many relationships and enums w/ values...then I'll be all set. :D
  • When using this code it triggers this warning, for what seems like every field. Do you have any suggestions on a fix? Here's the warning: Warning! ErrorException [ Warning ]: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash COREPATH/classes/database/pdo/connection.php @ line 209: 208: {
    209: if ( ! is_null($like) and preg_match($like, $row)) continue;
    210: list($type, $length) = $this->_parse_type($row);
  • Looks like a bug in the PDO connection driver, $like doesn't have any regex delimiters added to it. I've committed a fix for this.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion