>>> philosophy.courses['1'].__name__ u'1' >>> philosophy.courses['1'].__parent__ is philosophy.courses True """ from megrok import rdb from sqlalchemy import Column, ForeignKey from sqlalchemy.types import Integer, String from sqlalchemy.orm import relation metadata = rdb.MetaData() rdb.metadata(metadata) class Courses(rdb.Container): pass class Department(rdb.Model): id = Column('id', Integer, primary_key=True) name = Column('name', String(50)) courses = relation('Course', backref='department', collection_class=Courses) class Course(rdb.Model):
class MyClass(rdb.Model): rdb.metadata(rdb.MetaData()) rdb.tableargs(ForeignKeyConstraint(['id'], ['whah.id']), schema='bar') id = Column(Integer, primary_key=True)
class MyClass(rdb.Model): rdb.metadata(rdb.MetaData()) rdb.tableargs(schema='bar') id = Column(Integer, primary_key=True)
class MyClass(rdb.Model): rdb.metadata(rdb.MetaData()) id = Column(Integer, primary_key=True)
... print key, value.name, value.department.name 1 Logic Philosophy 2 Ethics Philosophy 3 Metaphysics Philosophy """ import grok from megrok import rdb from sqlalchemy import Column, ForeignKey from sqlalchemy.types import Integer, String from sqlalchemy.orm import relation metadata = rdb.MetaData() rdb.metadata(metadata) class Courses(rdb.Container): pass class Department(rdb.Model): id = Column("id", Integer, primary_key=True) name = Column("name", String(50)) courses = relation("Course", backref="department", collection_class=Courses) class Course(rdb.Model): id = Column("id", Integer, primary_key=True) department_id = Column("department_id", Integer, ForeignKey("department.id"))
class User(rdb.Model): rdb.metadata(metadata) rdb.table(user_table)