SET and ENUM support

thread: 6 messages  |  last: about 5 years ago  |  started: thursday, december 29, 2005, 8:24 am pst


#1  |  drydenmaker (Montana)
Thursday, December 29, 2005, 8:24 AM PST

It would be really nice if the SET or ENUM data types were recognized.  Like if there were only two values it would generate a check box, and if there were more it would give you radio buttons.

#2  |  Netino (Sao Paulo, Brasil)
Thursday, December 29, 2005, 9:10 AM PST

Or a combo box...

#3  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, January 2, 2006, 10:26 PM PST

I think it'd definitely be nice if someone wanted to update some of the templates and post it to the downloads section for other people to use/share, but it likely wouldn't be part of the core Qcodo release... mostly because SET and ENUM are both MySQL-specific constructs, and aren't really supported in other DB platforms.

The way Qcodo attempts to offer SET and ENUM-like functionality, but in a way that (we believe) is much more extensible as well as platform-independent is through the use of _type tables.

You can define a person_type table, and instead of having a ENUM column in your person table, you can simply have your person table FK to person_type, and achieve the same results:

person_type would have two columns: id and name.
person could have the following colums:
  first_name VARCHAR
  last_name VARCHAR
  person_type_id UNSIGNED INT (FK's to person_type.id)

And lastly the person_type table would have the following values:
1 - Manager
2 - Director
3 - Employee
4 - HR
etc.



for SET support, you should be able to create a person_persontype_assn table that has:
person_id (which FKs to person.id)
person_type_id (which FKs to person_type.id)

And it should code generate the ability similar to SET. (haven't tested this out yet -- so if it doesn't work, let us know)

#4  |  drydenmaker (Montana)
Saturday, January 7, 2006, 2:06 PM PST

Sure.  I appreciate the insight into the reason not to implement such support.  The main reason I made the request is because sometimes I use three state fields, like 'yes,no,maybe'.  But, like you pointed out a simple  separate table for this could be setup.  The first problem I thought of with this is that having a bunch of tables with three or four records in them causes clutter.  But this isn't much of a problem since I use the same three states in a lot of different places. So I just FK them all to one table.  If I get time, or if someone else does, it would be nice to have a patch to support this anyway.

#5  |  Shannon Pekary (East Palo Alto, CA) United States of America Qcodo Core Contributor
Thursday, June 15, 2006, 1:54 PM PDT

Something that seems to be missing that I discovered is that type tables must start with an ID of 1 and be sequential after that. I tried starting with 0, and got an “invalid” error when I went to the generated form. Starting with 1 made the error go away. Probably should mention this in the example at qcodo/examples/more_codegen/type_tables.php

#6  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Tuesday, July 18, 2006, 3:20 PM PDT

Hmm... was this with 0.2.12?  b/c we've updated the type tables logic so that it supports arbitrary numeric IDs now...



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.