Created
December 12, 2012 15:08
-
-
Save tefra/4268504 to your computer and use it in GitHub Desktop.
Lithium Model Manual Schema Decleration Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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