Referrers #59

Merged
merged 8 commits into from Aug 29, 2011

Projects

None yet

4 participants

@starkj
Contributor
starkj commented Aug 25, 2011

first of all: sry, i screwed up the commit history here again :-(

Well this is support for referrers.
This patch provides the new annotation "Referrers".
By default a property of this type stores all referrers (weak and hard) in a collection.
You can specify the option "referenceType" with the values "weak" and "hard" (or null) to only get the one or the other type of referring documents (or both types)
Then there is the option "filterName". It's value is passed to the method "get(Weak)References". Actually the option passed to "get(Weak)References" is called "name" in the spec. I named it "filterName" here as "name" is already assigned.

@stof
Member
stof commented Aug 25, 2011

you should rebase your branch on top of doctrine/master and then force the push on github to clean this history:

git fetch doctrine
git checkout referrers
git rebase doctrine/master
git push origin referrers --force
uwej711 and others added some commits Aug 23, 2011
@uwej711 uwej711 Fix metadata loading of builtin documents
The wrapped metadata driver ensures that metadata for the builtin
documents is loaded. Still the DoctrineAnnotations need to be registered
with the AnnotationRegistry.
f2f9870
Johannes Stark referrer annotation 42c24a3
Johannes Stark added support for hard and weak referrers 5fb699f
@dbu dbu doing the code cleanup brian proposed 8785fa3
Johannes Stark removed option "all" for referenceType, new test, text fixes f11fcf8
Johannes Stark Merge remote branch 'doctrine/master' into referrers d3181d8
Johannes Stark fix typo 0d0becd
@starkj
Contributor
starkj commented Aug 26, 2011

thx for support @stof
at last that was all i could do using git rebase -i

@dbu dbu commented on the diff Aug 27, 2011
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php
@@ -520,6 +525,22 @@ class ClassMetadataInfo implements ClassMetadata
$this->childrenMappings[$mapping['fieldName']] = $mapping;
}
+ public function mapReferrers(array $mapping)
+ {
+ $mapping = $this->validateAndCompleteReferrersMapping($mapping, false);
+ $mapping['name'] = $mapping['fieldName'];
+ $this->referrersMappings[$mapping['fieldName']] = $mapping;
+ }
+
+ protected function validateAndCompleteReferrersMapping($mapping)
+ {
+ $mapping = $this->validateAndCompleteFieldMapping($mapping, false);
+ if (!(array_key_exists('referenceType', $mapping) && in_array($mapping['referenceType'], array(null, "weak", "hard")))) {
@dbu
dbu Aug 27, 2011 Member

phpcr defaults to REFERENCE (that would be "hard" here) if nothing is specified. we could also default to that so people don't need to specify.

what do others think?

@dbu
dbu Aug 27, 2011 Member

aw crap, sorry. its 2 separate methods getReferences and getWeakReferences, so no default is fine.

@dbu
Member
dbu commented Aug 27, 2011

thanks for this work johannes! code looks good to me.
one request: could you update the README too, so we have a bit of documentation? explain the weak / hard and the name filter...

Johannes Stark updating README c40787c
@starkj
Contributor
starkj commented Aug 29, 2011

just updated the README and the wiki...

@dbu
dbu commented on c40787c Aug 29, 2011

this is not very consistent: Children uses filter= to filter on the name (permitting wildcards). Referrers uses filterName to only get references with a specific name (no wildcards allowed). i would suggest calling the Referrers attribute "name" as well, because its exactly one name that can be put there.

eventually, we should also fix the readme to specify what is optional and what is required, but that has nothing to do with this pull request.

Owner

this was my first thought as well to call the attriute "name". but "name" is already assigned. and its actually not a filter like the filter for children. so my choise was filterName.

@dbu dbu merged commit b554c05 into doctrine:master Aug 29, 2011
@dbu
Member
dbu commented Aug 29, 2011

ok, makes sense. thanks for this feature, johannes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment