From f5ad64a0a1c6720100ed52395cf530bc6016a212 Mon Sep 17 00:00:00 2001 From: Bob Fanger Date: Fri, 17 May 2013 17:06:32 +0200 Subject: [PATCH] Missing property now throws an Exception. --- classes/Repository.php | 9 ++++++++- tests/RepositoryTest.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/Repository.php b/classes/Repository.php index c7410e4..dc828ff 100644 --- a/classes/Repository.php +++ b/classes/Repository.php @@ -1516,7 +1516,14 @@ protected function convertToInstance($data, $config, $index = null, $reload = fa } } if (count($properties) !== 0) { - warning('Missing mapping for property: '.$config->class.'->'.human_implode(' and ', array_keys($properties)), 'Add "'.current(array_keys($properties)).'" to the ModelConfig->properties or to ModelConfig->ignoreProperties if the property wont be stored in the backend.'); + $causes = array( + '1. The column is missing in the backend/database.', + '2. The relation/foreign key is missing in the backend/database.', + '3. The column has diffent name than the property. Set the ModelConfig->properties[columname] = propertyname.', + '4. The property should be ignored by the repository. Add the property to the ModelConfig->ignoreProperties.', + '5. The relation couldn\'t be detected. Add an entry to ModelConfig->hasMany or ModelConfig->belongsTo.' + ); + throw new InfoException('Unexpected property: '.quoted_human_implode(' and ', array_keys($properties)).' in '.$config->class.' class for "'.$config->name.'"', 'Possible causes:
'.implode('
', $causes)); } $this->validated[$config->name] = true; } diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index 751e50f..d0e28a5 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -447,7 +447,7 @@ function test_missing_column() { $repo->getCustomer(1); $this->fail('The additional property/missing column should have given a notice.'); } catch (\Exception $e) { - $this->assertEquals('Missing mapping for property: \CustomerWithAnExtraProperty->extra', $e->getMessage(), $e->getMessage()); + $this->assertEquals('Unexpected property: "extra" in \CustomerWithAnExtraProperty class for "Customer"', $e->getMessage(), $e->getMessage()); } }