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

Why does GenericReferenceField wrap dbref ? #1185

Open
noirbizarre opened this issue Dec 13, 2015 · 0 comments
Open

Why does GenericReferenceField wrap dbref ? #1185

noirbizarre opened this issue Dec 13, 2015 · 0 comments

Comments

@noirbizarre
Copy link
Collaborator

@noirbizarre noirbizarre commented Dec 13, 2015

Hi !

In order to migrate some data to GenericReferenceField, I simply used a DBRef as defined in MongoDB documentation: https://docs.mongodb.org/v3.0/reference/database-references/
It took me some time and some code reading to understand that GenericReferenceField wraps DBRef in a {_cls: 'ClassName', _ref: DBRef} object.

So, I'm wondering why is GenericReferenceField using this pattern instead of the standard DBRef. It's harder to query, harder to read and to me the _cls is useless because:

  1. if the referenced document does not allow inheritance, there is only one class in the collection (which dbref provide)
  2. if the referenced document use inheritance, the _cls attribute is stored in the document itself so the collection is sufficient too

At first I was thinking that it permit, in the case of inheritance, to only fetch the required attribute on dereferencing but, it's not allowed anymore to store more field that the model has and this reasoning does not stand for DynamicDocument.

So can someone explain me this choice? Is there some historical reason ? Am I missing something ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.