ming nested subdocument using imperative mapping

瀏覽次數:26 次
跳到第一則未讀訊息

Rafael Ribeiro

未讀,
2020年12月21日 上午9:33:112020/12/21
收件者: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

未讀,
2020年12月22日 清晨6:27:192020/12/22
收件者: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

未讀,
2020年12月22日 上午8:54:162020/12/22
收件者: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

未讀,
2020年12月22日 上午9:12:252020/12/22
收件者: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

未讀,
2020年12月22日 上午9:16:292020/12/22
收件者: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.

回覆所有人
回覆作者
轉寄
0 則新訊息