-
-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
storeAs option for references #1349
Changes from all commits
d81f1e9
11f7a2a
a78ff55
3b4851c
c8f2afb
60fad18
003dccf
c6b20e2
618b833
14b921b
f2ceef5
2a3f77a
b0a7256
ed0a32c
7e2ee3c
2c6d6ab
4e1a748
07082a5
191c63f
bde7416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,13 @@ class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMet | |
const MANY = 'many'; | ||
const ONE = 'one'; | ||
|
||
/** | ||
* The types of storeAs references | ||
*/ | ||
const REFERENCE_STORE_AS_ID = 'id'; | ||
const REFERENCE_STORE_AS_DB_REF = 'dbRef'; | ||
const REFERENCE_STORE_AS_DB_REF_WITH_DB = 'dbRefWithDb'; | ||
|
||
/* The inheritance mapping types */ | ||
/** | ||
* NONE means the class does not participate in an inheritance hierarchy | ||
|
@@ -1181,7 +1188,20 @@ public function mapField(array $mapping) | |
$mapping['nullable'] = false; | ||
} | ||
|
||
if (isset($mapping['reference']) && ! empty($mapping['simple']) && ! isset($mapping['targetDocument'])) { | ||
// Synchronize the "simple" and "storeAs" mapping information for backwards compatibility | ||
if (isset($mapping['simple']) && ($mapping['simple'] === true || $mapping['simple'] === 'true')) { | ||
$mapping['storeAs'] = ClassMetadataInfo::REFERENCE_STORE_AS_ID; | ||
} | ||
// Remove the "simple" mapping and use "storeAs" in all further logic | ||
if (isset($mapping['simple'])) { | ||
unset($mapping['simple']); | ||
} | ||
|
||
if (isset($mapping['reference']) | ||
&& isset($mapping['storeAs']) | ||
&& $mapping['storeAs'] === ClassMetadataInfo::REFERENCE_STORE_AS_ID | ||
&& ! isset($mapping['targetDocument']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not having a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alcaeus I'm not quite sure how I can fetch the mapping for the targetDocument in the ClassMetadataInfo class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately you can't, IMO that could be detected at the runtime but I have a feeling there's way more things than references that could bite you in such cases so that wouldn't be my main concern :) |
||
) { | ||
throw MappingException::simpleReferenceRequiresTargetDocument($this->name, $mapping['fieldName']); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mentioned this in the original PR (#807 (comment)) and I'll mention it again:Expr::references
andExpr::includesReferenceTo
currently rely on the$db
option being set when notargetDocument
is given.Correction: you're handling this in ClassMetadataInfo. Good job 👍