ming nested subdocument using imperative mapping

26 views
Skip to first unread message

Rafael Ribeiro

unread,
Dec 21, 2020, 9:33:11 AM12/21/20
to TurboGears
Hi all,

 I am porting an application from mongoengine to ming and I wished to map a nested document. I've seen another post mentioning the subdocument feature but since I am not using the declarative approach to mapping I'd like to know whether it is possible to do it using the imperative mapping approach ( https://ming.readthedocs.io/en/latest/baselevel.html#ming-baselevel ).
 Is it possible to load an object and have another class nested inside?

best regards,
Rafael

Vincenzo Castiglia

unread,
Dec 22, 2020, 6:27:19 AM12/22/20
to turbo...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/turbogears/9e80790c-5260-4485-a8cc-ddbbddfdfd4dn%40googlegroups.com.

Rafael Ribeiro

unread,
Dec 22, 2020, 8:54:16 AM12/22/20
to turbo...@googlegroups.com
Not exactly since it'll convert back to a ming.base.Object as per the documentation. I was looking for something that would be able to convert back to an arbitrary class from my code.

You received this message because you are subscribed to a topic in the Google Groups "TurboGears" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/turbogears/i2K3aaIe8GQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to turbogears+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/turbogears/CABFU5vsmWAdzrR_ASBd3kafL-Ru4WiqViaVbbywCOb3o8y7JKg%40mail.gmail.com.

Vincenzo Castiglia

unread,
Dec 22, 2020, 9:12:25 AM12/22/20
to turbo...@googlegroups.com
ok, then what about subclassing like this
```
class MyConverter(schema.Object):
    def _validate(self, d, allow_extra=False, strip_extra=False):
        return MyClass(super()._validate(d, allow_extra=allow_extra, strip_extra=strip_extra))
```
assuming your class have a __init__ that takes a dict or is a subclass of collections.UserDict

Rafael Ribeiro

unread,
Dec 22, 2020, 9:16:29 AM12/22/20
to turbo...@googlegroups.com
Looks promising ... but how should I register this converter and is it possible to have more than one converter registered for schema.Object? In case I have two or more places in which I have nested objects like this. I have the impression that ming lacks the properties parameter in the mapper function and also lacks a relationship function just like SQLAlchemy does on this scenario.

Reply all
Reply to author
Forward
0 new messages