SQL Alchemy related Objects Error

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-04-14T13:29:44Z Indexed on 2010/04/14 13:33 UTC
Read the original article Hit count: 398

Filed under:
|
|
from sqlalchemy.orm import relation, backref
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, Date, Sequence
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

class GUI_SCENARIO(Base):
    __tablename__ = 'GUI_SCENARIO'
    Scenario_ID = Column(Integer, primary_key=True)
    Definition_Date = Column(Date)

    guiScenarioDefinition = relation('GUI_SCENARIO_DEFINITION',
        order_by='GUI_SCENARIO_DEFINITION.Scenario_Definition_ID', 
        backref='guiScenario')

    def __init__(self, Scenario_ID=None, Definition_Date=None):
        self.Scenario_ID = Scenario_ID
        self.Definition_Date = Definition_Date

class GUI_SCENARIO_DEFINITION(Base):
    __tablename__='GUI_SCENARIO_DEFINITION'
    Scenario_Definition_ID = Column(Integer, Sequence('Scenario_Definition_ID_SEQ'), primary_key=True)
    Scenario_FK = Column(Integer, ForeignKey('GUI_SCENARIO.Scenario_ID'))
    Definition_Date=Column(Date)
    guiScenario = relation(GUI_SCENARIO, backref=backref('guiScenarioDefinition', order_by=Scenario_Definition_ID))
    def __init__(self, Scenario_FK, Definition_Date):
        self.Scenario_FK = Scenario_FK
        self.Definition_Date = Definition_Date

    guiScenario = relation(GUI_SCENARIO, 
        backref=backref('guiScenarioDefinition', 
            order_by=Scenario_Definition_ID))
        tableNameScenario = "GUI_SCENARIO"
        scenarioClass = getattr(MappingTablesScenario, tableNameScenario)
        tableScenario = Table(tableNameScenario, meta, autoload=True)
        mapper(scenarioClass, tableScenario)


        scenarioName = scenarioDefinition.name
        scenarioDefinitionDate = datetime.today()
        newScenario = MappingTablesScenario.GUI_SCENARIO(scenarioName, 
                                                         scenarioDefinitionDate)
        print newScenario.guiScenarioDefinition

If I try to get the objects related to a scenarioObject, I always get this error:

AttributeError: 'GUI_SCENARIO' object has no attribute 'guiScenarioDefinition'

Does anyone know, why I get this error?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy