Skip to content

Loading…

Throw an error when the identifier field is not available #62

Merged
merged 1 commit into from

2 participants

@phaikawl

I accidentally mapped an empty class, then I got 2 errors: "Undefined index: in ...Doctrine/ODM/CouchDB/Mapping/ClassMetadata.php", "Fatal error: Call to a member function getValue() on a non-object in .../Doctrine/ODM/CouchDB/Mapping/ClassMetadata.php".
the erroring part is reflFields[$this->identifier].
The reason is, there's no id field, it's a bit confusing and it wastes new user's time.
So there should be an error message.

@phaikawl phaikawl Class Metadata: Throw a nice error message when the identifier field …
…is not available, instead of letting the user confused with PHP's Undefined index and another fatal PHP error.
7090fdc
@beberlei beberlei merged commit 77f5b5b into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2013
  1. @phaikawl

    Class Metadata: Throw a nice error message when the identifier field …

    phaikawl committed
    …is not available, instead of letting the user confused with PHP's Undefined index and another fatal PHP error.
View
1 lib/Doctrine/ODM/CouchDB/Mapping/ClassMetadataFactory.php
@@ -83,6 +83,7 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
if ($this->getDriver()) {
$this->getDriver()->loadMetadataForClass($class->getName(), $class);
}
+ $class->checkUp();
}
/**
View
9 lib/Doctrine/ODM/CouchDB/Mapping/ClassMetadataInfo.php
@@ -247,6 +247,15 @@ public function getIdentifier()
}
/**
+ * Check for any possible shortcomings in the class
+ */
+ public function checkUp() {
+ if (!isset($this->identifier)) {
+ throw new MappingException('An identifier field is required.');
+ }
+ }
+
+ /**
* Get identifier field names of this class.
*
* Since CouchDB only allows exactly one identifier field this is a proxy
Something went wrong with that request. Please try again.