Skip to content
Snippets Groups Projects
Commit 23859ce2 authored by Jared Hancock's avatar Jared Hancock
Browse files

Throw error if relationship reverse is misconfigured

parent 205e7185
Branches
Tags
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
**********************************************************************/ **********************************************************************/
class OrmException extends Exception {} class OrmException extends Exception {}
class OrmConfigurationException extends Exception {}
class VerySimpleModel { class VerySimpleModel {
static $meta = array( static $meta = array(
...@@ -111,7 +112,7 @@ class VerySimpleModel { ...@@ -111,7 +112,7 @@ class VerySimpleModel {
static function _inspect() { static function _inspect() {
if (!static::$meta['table']) if (!static::$meta['table'])
throw new OrmConfigurationError( throw new OrmConfigurationException(
'Model does not define meta.table', get_called_class()); 'Model does not define meta.table', get_called_class());
// Break down foreign-key metadata // Break down foreign-key metadata
...@@ -120,6 +121,9 @@ class VerySimpleModel { ...@@ -120,6 +121,9 @@ class VerySimpleModel {
list($model, $key) = explode('.', $j['reverse']); list($model, $key) = explode('.', $j['reverse']);
$info = $model::$meta['joins'][$key]; $info = $model::$meta['joins'][$key];
$constraint = array(); $constraint = array();
if (!is_array($info['constraint']))
throw new OrmConfigurationException(
$j['reverse'].': Reverse does not specify any constraints');
foreach ($info['constraint'] as $foreign => $local) { foreach ($info['constraint'] as $foreign => $local) {
list(,$field) = explode('.', $local); list(,$field) = explode('.', $local);
$constraint[$field] = "$model.$foreign"; $constraint[$field] = "$model.$foreign";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment