The current ORM for Mongo DB shipped with Tori 2.0 does not fully support relational mapping.
The idea is that supposing we have two documents, namely Foo and Bar respectively, where Foo has an embedded document Bar (on bar property), then the code should look like as followed.
from tori.db.document import document
from tori.db.mapper import embed, AssociationType
@document
class Bar(object):
def __init__(self, blah):
self.blah = blah
@document
@embed(
'bar', # property
Bar, # target
AssociationType.ONE_TO_ONE # association_type
)
class Foo(object):
def __init__(self, bar, _id=None):
self.bar = bar
where the association is always UNIDIRECTIONAL from the main document to any embedded documents and the type of association (AssociationType) can be only ONE_TO_ONE and ONE_TO_MANY. The type is automatic by default.
Please note that anything with MANY will use a special list-based class and it doesn't support dict-type on the "many" end.
The current ORM for Mongo DB shipped with Tori 2.0 does not fully support relational mapping.
The idea is that supposing we have two documents, namely Foo and Bar respectively, where Foo has an embedded document Bar (on
bar
property), then the code should look like as followed.where the association is always UNIDIRECTIONAL from the main document to any embedded documents and the type of association (
AssociationType
) can be only ONE_TO_ONE and ONE_TO_MANY. The type is automatic by default.Please note that anything with MANY will use a special list-based class and it doesn't support dict-type on the "many" end.