====== Binding a Table to a Model ====== ===== Table Name ===== Every Model is backed by exactly one table. The _table_name property defines which table this is. If table name is not set, Solar will guess a table name based on the class of the model. The rules for deducing the table name are complicated and I don't understand them. FIXME You can also explicitly set the table_name $this->_table_name = 'table'; ===== Table Cols ===== The _table_cols property holds a definition of the columns of the table that drives the model. Normally, Solar will query your database and retrieve the column definitions. These will be cached for performance. Each column definition is an array with the following elements ^ Key ^ Definition ^ | name | Name of the column (string) | | type | Type of the column (string) | | size | Column size (integer) | | scope | Decimal Places (integer) | | default | Default value for this column (Mixed) | | require | is this a required (non-null) column? | | primary | is this part of the primary key? | | autoinc | auto-incremented? | Solar has the following Standard Column Types ^ Type ^ Definition ^ | char | A fixed-length string of 1-255 characters.| | varchar | A Variable-length string of 1-255 characters.| | bool | A true/false boolean, generally stored as an integer 1 or 0.| | smallint | A 2-byte integer in the range of -32767 ... +32768.| | int | A 4-byte integer in the range of -2,147,483,648 ... +2,147,483,647.| | bigint | An 8-byte integer, value range roughly (-9,223,372,036,854,780,000 ... +9,223,372,036,854,779,999). | | numeric | A fixed-point decimal number of a specific size (total number of digits) and scope (the number of those digits to the right of the decimal point).| | float | A double-precision floating-point decimal number.| | clob | A character large object with a size of up to 2,147,483,647 bytes (about 2 GB).| | date | An ISO 8601 date; for example, '1979-11-07'.| | time | An ISO 8601 time; for example, '12:34:56'.| | timestamp | An ISO 8601 timestamp without a timezone offset; for example, '1979-11-07 12:34:56'.| columns declared in tables not in this list will be listed as FIXME. There are two cases where you might want to declare your own column definitions in _setup. Otherwise, allow Solar to read them from the Database. ==== Defining Table Cols to Avoid Table Describe ==== Solar issues a DESCRIBE table_name call in order to pull down column definitions. This is cached, but for performance reasons, you may wish to override this behavior. You can define your columns in the _setup method and set the configuration option table_scan to false. This will cause Solar to use the definitions in the model regardless of the table. Normally, table_scan is true, and would overwrite any columns you define with their table definitions. ==== Defining Table Cols for Table Creation ==== The other case where you might want to define columns in the _setup method is to allow Solar to create tables that do not exist. If the table_scan configuration is true and the table does not exist, Solar will attempt to create the table based on the columns you have defined in your _setup method. There isno way to prevent solar from trying to create a table, even if the columns are not defined. ==== Defining Indexes for Table Creation ==== In the event that a table will be created, the _index property will be used to create indexes. This property is unused outside of table creation.