Skip to content

Instantly share code, notes, and snippets.

@tefra
Created December 12, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tefra/4268504 to your computer and use it in GitHub Desktop.
Save tefra/4268504 to your computer and use it in GitHub Desktop.
Lithium Model Manual Schema Decleration Fix
public static function schema($field = null) {
$self = static::_object();
if(is_array($self->_schema) && !empty($self->_schema)) {
$schema = static::$_classes['schema'];
$fields = $self->_schema;
$self->_schema = new $schema(compact('fields'));
}
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment