Fields related configuration
Introduction
Fields are defined in the "meta_fields" array of a record class. Each key present in the array represent the name of the record property while its value is an array of configuration. By convention, fields take a singular form for standart properties, but they may take a plural form for associated records expecting zero or more associated records.
Property "type"
This property is tightly coupled with the database type of field. It may take the following values:
- Type "int"
Map the value to an integer. The "int" type is automatically used if the field is expected to store a primary key or a foreign key. Setting a numerical string value will be automatically converted to an "int" value. The type of field defined in the database (tinyint,smallint,mediumint,int,bigint) and wether it is marked as unsigned or not depends of the settings of the "min" and "max" properties. To create an "unsigned" field, simply set the "min" property to 0. By default, the field is set to "int(11)". For primary keys and foreign keys, the field is also set as "unsigned". - Type "text"
Map the value to a string. The type of field defined in the database (char,varchar,tinytext,text,mediumtext,longtext) depends of the settings of the "min" and "max" properties. - Type "boolean"
Map the value to a boolean variable. For provided integer, the value is casted ("0" and "1" are respectively mapped to boolean "false" and "true"), Nor provided string "", "0" and "false" map to boolean "false" while others string map to boolean "true". Also, "null" values map to false. If a "default" property is not provided, it is automatically set and default to "false". "Boolean" are stored in the database as "tinyint(1)" fields. - Type "float"
Map the value to a "float" variable. Provided values are automattically casted to a "float" variable type. - Type "double"
Map the value to a "double" variable. Provided values are automattically casted to a "double" variable type. - Type "password"
Map the value to a "string" variable processed by the "md5" function. By default, Password are not returned by the "toArray" method. - Type "json"
Map the value to a "php" array. The array is serialized in the database as a JSON string.
Property "min"
Define the minimum value. The "min" property is used to validate the record as well as to defined the field in the method "$table->update".
Default value is determined as follow:
- "type" is "int" and "max" is not defined: default value is "-2147483648" (signed "int")
- "type" is "int" and "max" value is defined and greater than "2147483647": default value is "0" (unsigned "int")
- "type" is "int" and "max" value is defined and lower or equals to "2147483647": default value is "-2147483648" (signed "int")
- "type" is "text": default value is "0"
Property "max"
Define the maximum value. The "max" property is used to validate the record as well as to defined the field in the method "$table->update"
- "type" is "int" and "min" is not defined: default value is "2147483647" (signed "int")
- "type" is "int" and "min" value is defined and greater or equals to "0": default value is "4294967295" (unsigned "int")
- "type" is "int" and "min" value is defined and lower than "0": default value is "2147483647" (signed "int")
- "type" is "text": default value is "0"
Property "default"
Provide a default value if a record property is not set.
Additional properties
Plugins such as the "assocations", "hierarchical" and "order" plugins may add additionnal properties.