Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Partial reference support (without $db property) #807

wants to merge 1 commit into from

Conversation

sokac
Copy link

@sokac sokac commented Feb 24, 2014

This PR introduces new annotation property ##partial## for ReferenceOne and ReferenceMany which, when set to true, will create a reference with no $db key.

@sokac
Copy link
Author

sokac commented Mar 18, 2014

Does commit look good? It doesn't break old code and brings new functionality.

@jmikola jmikola added the feature label Apr 1, 2014
);
if ( empty($referenceMapping['partial'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space before empty(

@jwage
Copy link
Member

jwage commented Mar 28, 2015

This PR is missing support for the other mapping drivers (xml, yaml, etc.)

@jwage
Copy link
Member

jwage commented Mar 28, 2015

Also, could you explain the reasoning behind wanting to do this?

@sokac
Copy link
Author

sokac commented May 15, 2015

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 )

@solocommand
Copy link
Contributor

@sokac the $db parameter is optional at the server level for the reference to be valid, however it's currently required for the odm to support references across databases.

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 $db parameter in all DBRefs.

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.

@sokac
Copy link
Author

sokac commented May 20, 2015

Makes sense completely. Maybe documentation could be update to reference this potential issue.

@sokac sokac closed this May 20, 2015
@jmikola
Copy link
Member

jmikola commented Jun 8, 2015

Sorry, just noticed this after @malarzm linked me. Indeed, this is something we'd like to do, as $db is basically useless for single-database applications. We have a tracking ticket for this in #802.

I think we can re-open this for later review. Thanks for the initial PR!

@jmikola jmikola reopened this Jun 8, 2015
@jmikola jmikola added this to the 1.0.0 milestone Jun 9, 2015
@malarzm
Copy link
Member

malarzm commented Jul 18, 2015

LGTM, just need to mention this in the docs. @jmikola @jwage @alcaeus thoughts?

);
if ( empty($referenceMapping['partial'])) {
$dbRef['$db'] = $this->getDocumentDatabase($class->name)->getName();
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely 👍 for catching this

@alcaeus
Copy link
Member

alcaeus commented Jul 18, 2015

I'm not quite sure about the partial parameter, especially since we already have simple. With this PR we'd have three different kinds of references:

  • "simple" references that are simply just an identifier and contain no other mapping types (currently mapped using simple = true),
  • "non-simple" but "partial" references that create a DBRef object but don't include a $db key (currently mapped using partial = true), and
  • "full" references that create a complete DBRef object (currently mapped using simple = false and partial = false)

In my opinion it might be smarter to deprecate the simple parameter and introduce a new parameter that takes the values simple, partial and full (with full being the default value). Unfortunately, type is already taken, so we'd need to find another wording that clearly indicates what we're trying to do here.

@coudenysj
Copy link
Contributor

I agree with the approach of @alcaeus.

type would be the obvious option, maybe we could introduce dbRefType?

@malarzm
Copy link
Member

malarzm commented Jan 15, 2016

I'd throw storeAs to the proposition pool and ultimately ask @jmikola for a word proposition/judgment :)

@coudenysj
Copy link
Contributor

Sounds good too! :)

@alcaeus
Copy link
Member

alcaeus commented Jan 16, 2016

👍 to using storeAs as it's more descriptive than type.

@malarzm malarzm modified the milestones: 1.1.0, 1.x Jun 9, 2016
@malarzm
Copy link
Member

malarzm commented Jun 9, 2016

Superseded by #1349 which is now available in 1.1.0 :)

@malarzm malarzm closed this Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants