lithium\data\Model::schema PHP Method

schema() public static method

..)` to define the schema manually.
public static schema ( mixed $field = null ) : array | lithium\data\Schema
$field mixed Optional. You may pass a field name to get schema information for just one field. Otherwise, an array containing all fields is returned. If `false`, the schema is reset to an empty value. If an array, field definitions contained are appended to the schema.
return array | lithium\data\Schema
    public static function schema($field = null)
    {
        $self = static::_object();
        if (!is_object($self->_schema)) {
            $self->_schema = static::connection()->describe($self::meta('source'), $self->_schema, $self->_meta);
            if (!is_object($self->_schema)) {
                $class = get_called_class();
                throw new ConfigException("Could not load schema object for model `{$class}`.");
            }
            $key = (array) $self::meta('key');
            if ($self->_schema && $self->_schema->fields() && !$self->_schema->has($key)) {
                $key = implode('`, `', $key);
                throw new ConfigException("Missing key `{$key}` from schema.");
            }
        }
        if ($field === false) {
            return $self->_schema->reset();
        }
        if (is_array($field)) {
            return $self->_schema->append($field);
        }
        return $field ? $self->_schema->fields($field) : $self->_schema;
    }

Usage Example

Example #1
0
 public static function schema($field = null)
 {
     if (is_array($field)) {
         return static::_object()->_schema = $field;
     }
     return parent::schema($field);
 }
All Usage Examples Of lithium\data\Model::schema