-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum Support #1
Comments
History: TheSavior: vlucas: TheSavior: http://msdn.microsoft.com/en-us/library/ms177603.aspx vlucas: Specific driver implementations will use whatever they need to in order to implement the functionality most efficiently. MySQL uses TINYINT(1), and SQL Server could use "bit". The only important detail is that the values on the actual entity are always either true, false, or null (no value). |
Hi there, is there any progress to this feature request? |
If enum support doesn't have to be native then something like this could fairly easily be added using the existing type system like this: 'colours' => array('type' => 'enum', 'fields' => array('red', 'green', 'blue')) and internally the value could be stored as the integer index of the field. @vlucas Thoughts? |
I was actually thinking something very similar, only I kind of want to use 'status' => array('type' => 'select', 'options' => array('published', 'draft', 'deleted')) Native enum support would store the value of the selected type, like "published", but I would really like support for just storing the key, so you could even use an explicitly defined array: 'status' => array(
'type' => 'select',
'options' => array(
'published' => 'Published (Publicly Visible)',
'draft' => 'Draft (Not Publicly Visible)',
'deleted' => 'Deleted'
)
) Spot would store the value if the array is numerically-indexed, and use the key if its an associative array. Maybe there would also be an option to force Spot to store the index even if the database type supports enum directly. Maybe something like This would allow you to populate dropdowns and expose the options in your API in a much easier and more straightforward way. Validation on the type (via the type system) would also have to check to ensure the set value is one of the options in the array (or the key if the option is set). I would love further discussion and/or thoughts/feedback on this topic. |
My immediate feeling is that we would want database integrity to be handled as much as possible by the database. A big issue with trying to do this completely natively is that some dbms don't support enums. However I think I can be convinced on handling it in Spot since the issues with trying to be native are large and not very user friendly. I don't know if I agree about putting the nice pretty directly in a Spot Entity. That seems like something that should be in the application level logic. I feel like the database is for storing data, and the ORM is designed for easy access to that data, not for formatting that data in a way that it is necessarily ready to be printed to the user. |
Maybe the answer is to just dodge it for now. I can go ahead and add a |
We need to make sure that there is support for enum's and sets when defining entity structure.
Something like the following may work:
This issue is copied from https://github.com/actridge/Spot/issues/1
The text was updated successfully, but these errors were encountered: