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

Need a simple way to get id of ReferenceField #456

Open
anti-social opened this issue Mar 6, 2012 · 0 comments
Open

Need a simple way to get id of ReferenceField #456

anti-social opened this issue Mar 6, 2012 · 0 comments

Comments

@anti-social
Copy link

Sometimes I need to get reference field id but way I do this is ugly. As I understand if I get value of reference field there will be additional query to mongo.

So I need to write something like that:

class MyDoc(Document):
    other_doc = ReferenceField('AnotherDoc')

d = MyDoc.objects(id=object_id).first()
other_doc_dbref = d._data.get('other_doc')
other_doc_id = other_doc_dbref.id if other_doc_dbref else None

I think this should be easier.

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

No branches or pull requests

1 participant