diff --git a/tests/mongodb/models.py b/tests/mongodb/models.py index 8e46cab0..fd9b48aa 100644 --- a/tests/mongodb/models.py +++ b/tests/mongodb/models.py @@ -1,6 +1,7 @@ from django.db import models -from djangotoolbox.fields import RawField +from djangotoolbox.fields import RawField, ListField, EmbeddedModelField from django_mongodb_engine.fields import GridFSField, GridFSString +from query.models import Post class DescendingIndexModel(models.Model): desc = models.IntegerField() @@ -46,5 +47,8 @@ class GridFSFieldTestModel(models.Model): gridstring = GridFSString() +class Issue47Model(models.Model): + foo = ListField(EmbeddedModelField(Post)) + RawModel.objects.all().delete() RawModel.objects.create(raw=42) diff --git a/tests/mongodb/tests.py b/tests/mongodb/tests.py index 08598099..8ea709de 100644 --- a/tests/mongodb/tests.py +++ b/tests/mongodb/tests.py @@ -100,6 +100,18 @@ def test_databasewrapper_api(self): for call in calls: call() +class RegressionTests(TestCase): + def test_issue_47(self): + """ ForeignKeys in subobjects should be ObjectIds, not unicode """ + from bson.objectid import ObjectId + from query.models import Blog, Post + post = Post.objects.create(blog=Blog.objects.create()) + m = Issue47Model.objects.create(foo=[post]) + collection = get_collection(Issue47Model) + assert collection.count() == 1 + doc = collection.find_one() + self.assertIsInstance(doc['foo'][0]['blog_id'], ObjectId) + class DatabaseOptionTests(TestCase): """ Tests for MongoDB-specific database options """