shiroyuki / Tori

Tornado-based Micro Web Framework
MIT License
3 stars 1 forks source link

Implement the object relational mapper (ORM) between a document and embed documents for Mongo DB #15

Open shiroyuki opened 11 years ago

shiroyuki commented 11 years ago

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.

shiroyuki commented 9 years ago

The work must be done from shiroyuki/passerine.