1

Could somebody explain why Drupal needs list (integer), list (float) AND list (text). What is the difference?

Values are set in key | value pairs. So:

  • list integer - saves key in database in integer format
  • list float - saves key in database in float format
  • list text - save key in database in varchar format

Why do we need list (float) and list (text), if we have list(integer)?

An explanation with examples would be great.

2 Answers 2

1

Occasionally you want to access a dropdown with Jquery - in this case it can be useful to have keys which are more than just integers.

Nothing I ever did, but you could use a dropdown to apply different classes to an element:

style-red|Red Layout
style-blue|Blue Layout

The value is the human readable label and the key is the class to switch around with jQuery. If you had used '1|Red Layout' and '2|Blue Layout' you need to tell JQuery that is has to translate key 1 into class style-red and key 2 into style-blue before applying them. So whenever you would add a new key|value pair you would not only need to edit your css but also your jQuery code, while using text keys you only need to edit the css file.

It is not a real world example, but you get the point.

For the float it is similar. Imagine you have a list with prices each with a human readable label plus a float you can instantly use for calculation in jQuery.

0
0

Why would you want to store non-integer data as an integer?

Why make your data hard to understand by assigning arbitrary integer values to everything if you can instead use descriptive values that can immediately be understood?

Basically, if your data is a string then store it as a string. The same goes for other data types.

Obfuscating your data by changing the data type for no reason is bad software/data-structure design and will make it harder for anyone that has to work on your system in future (including yourself).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.