-
-
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
Partial reference support (without $db property) #807
Conversation
Does commit look good? It doesn't break old code and brings new functionality. |
); | ||
if ( empty($referenceMapping['partial'])) { |
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.
Remove space before empty(
This PR is missing support for the other mapping drivers (xml, yaml, etc.) |
Also, could you explain the reasoning behind wanting to do this? |
Sorry for the delay. The reason behind this PR is our previous code base had partial db reference (i.e. not having db in DBRef). When you issue a query with DBRef with $db it yields different result than without one. Note that $db parameter is optional (http://docs.mongodb.org/manual/reference/database-references/#dbrefs ) |
@sokac the While I can see the advantage of allowing yourself to bypass that behavior, my approach would be to update the existing data to include the It's forward compatible if you are going to be moving forward with mongodb-odm, and should? be backwards compatible with your existing system. Not arguing for/against this PR, just pointing out another option. |
Makes sense completely. Maybe documentation could be update to reference this potential issue. |
); | ||
if ( empty($referenceMapping['partial'])) { | ||
$dbRef['$db'] = $this->getDocumentDatabase($class->name)->getName(); |
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.
Not always setting a $db
key can cause errors in Expr::references()
and Expr::includesReferenceTo()
when using the methods with a reference that has the partial
flag enabled and no targetDocument
set. I'm not sure how much of a use case this is, but either the Expr
class or the mapping drivers need to make sure to handle this case.
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.
definitely 👍 for catching this
I'm not quite sure about the
In my opinion it might be smarter to deprecate the |
I agree with the approach of @alcaeus.
|
I'd throw |
Sounds good too! :) |
👍 to using |
Superseded by #1349 which is now available in 1.1.0 :) |
This PR introduces new annotation property ##partial## for ReferenceOne and ReferenceMany which, when set to true, will create a reference with no $db key.