python - Dereference relations in MongoEngine embedded documents -


i have schema using mongoengine looks this

class user(db.document)     email = db.emailfield(unique=true)  class queueelement(db.embeddeddocument):     accepts = db.listfield(db.referencefield('resource'))     user = db.referencefield(user)  class resource(db.document):     name = db.stringfield(max_length=255, required=true)     current_queue_element = db.embeddeddocumentfield('queueelement')  class queue(db.embeddeddocument):     name = db.stringfield(max_length=255, required=true)     resources = db.listfield(db.referencefield(resource))     queue_elements = db.listfield(db.embeddeddocumentfield('queueelement'))  class room(db.document):     name = db.stringfield(max_length=255, required=true)     queues = db.listfield(db.embeddeddocumentfield('queue')) 

and return json object of room object include information queues (together referenced resources), , nested queue_elements ( referenced "accepts" references, , user references)

however, when want return room relationships dereferenced:

room = room.objects(slug=slug).select_related() if (room):     return ast.literal_eval(room.to_json()) abort(404) 

i don't dereferencing. get:

{    "_cls":"room",    "_id":{       "$oid":"552ab000605cd92f22347d79"    },    "created_at":{       "$date":1428842482049    },    "name":"second",    "queues":[       {          "created_at":{             "$date":1428842781490          },          "name":"myqueue",          "queue_elements":[             {                "accepts":[                   {                      "$oid":"552aafb3605cd92f22347d78"                   },                   {                      "$oid":"552aafb3605cd92f22347d78"                   },                   {                      "$oid":"552ab1f8605cd92f22347d7a"                   }                ],                "created_at":{                   "$date":1428849389503                },                "user":{                   "$oid":"552ac8c7605cd92f22347d7b"                }             }          ],          "resources":[             {                "$oid":"552aafb3605cd92f22347d78"             },             {                "$oid":"552aafb3605cd92f22347d78"             },             {                "$oid":"552ab1f8605cd92f22347d7a"             }          ]       }    ],    "slug":"secondslug" } 

even though i'm using select_related() function. believe because mongoengine may not follow references on embedded documents. note, can dereference in python if this:

room = room.objects(slug=slug).first().queues[0].queue_elements[0].accepts[0] return ast.literal_eval(room.to_json()) 

which yields

{    "_id":{       "$oid":"552aafb3605cd92f22347d78"    },    "created_at":{       "$date":1428842849393    },    "name":"myres" } 

which dereferenced resource document.

is there way can follow references on embedded documents? or coming because i'm following bad pattern, , should finding different way store information in mongodb (or indeed, switch relational db) ? thanks!


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -