rendered paste bodyanalysis_meta = Table('analysis_meta', metadata,
Column('meta_id', Integer, primary_key=True),
Column('analysis_id', Integer, ForeignKey('analysis_data.id'), nullable=False),
Column('start_time', DateTime, nullable=False),
Column('rank', Integer),
Column('created', DateTime, default=func.now()),
)
analysis_data = Table('analysis_data', metadata,
Column('id', Integer, primary_key=True),
Column('topic', Unicode(256), nullable=False),
Column('content', Unicode, nullable=False),
Column('created', DateTime, default=func.now()),
Column('updated', DateTime, default=func.now(), onupdate=func.now()),
)
class AnalysisMeta(object):
def __init__(self, start_time, end_time, ticker_id, rank=1):
self.start_time = start_time
self.ticker_id = ticker_id
self.rank = rank
class Analysis(object):
def __init__(self, topic, content):
self.topic = topic
self.content = content
mapper(AnalysisMeta, analysis_meta)
mapper(Analysis, analysis_data, properties={'meta': relation(AnalysisMeta)})
From shell:
In [23]: s = create_session()
In [24]: q = s.query(Analysis)
In [25]: l = q.options(lazyload('content'))
In [26]: l.selectfirst()
---------------------------------------------------------------------------
exceptions.AttributeError Traceback (most recent call last)
/home/ryalaman/stuff/daFinci/<ipython console>
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/query.py in selectfirst(self, *args, **params)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/query.py in select_whereclause(self, whereclause, params, **kwargs)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/query.py in compile(self, whereclause, **kwargs)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/interfaces.py in setup(self, querycontext, **kwargs)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/interfaces.py in _get_context_strategy(self, context)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/interfaces.py in _get_strategy(self, cls)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/strategies.py in init(self)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/orm/strategies.py in init(self)
AttributeError: 'ColumnProperty' object has no attribute 'primaryjoin'