lithium\data\Model::schema()

public static method

Lazy-initialize the schema for this Model object, if it is not already manually set in the object. You can declare protected $_schema = [...] to define the schema manually.

Parameters

  • mixed $field

    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.

Returns

array|lithium\data\Schema

Source

	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;
	}