Hi,

I've got a problem understanding how to handle relationships with
polymorphism
Sorry for the db design (I took it overs as it is ).

I've got a parent class Task

class Task(DBBASE):
    __tablename__ = 'task'
    id = Column(Integer, primary_key=True)
    amount = Column(Integer)

and two child classes

class Invoice(DBBASE):
    __tablename__ = 'invoice'
    id = Column(Integer, ForeignKey('task.id'), primary_key=True)
    date = Column(Date)
    project_id = Column(Integer, ForeignKey('project.id'))
    project = relationship("Project", backref=backref('invoices',
order_by='Invoice.date'))
    specific_attr1 = Column(Integer)

class Esimation(DBBASE):
    __tablename__ = 'estimation'
    id = Column(Integer, ForeignKey('task.id'), primary_key=True)
    date = Column(Date)
    project_id = Column(Integer, ForeignKey('project.id'))
    project = relationship("Project", backref=backref('estimations',
order_by='Invoice.date'))
    specific_attr2 = Column(Integer)
    specific_attr3 = Column(Integer)
   
I'd like to query something like:

dbession.query(Task).with_polymorphic([Invoice,
Estimation]).join(Invoice.project).join(Estimation.project).join(Project.client)

I actually get an error :
(1066, "Not unique table/alias: 'project' ")

1- I've tried to add a aliased=True to the with_polymorphic call, but it
gives me "<lambda>() got an unexpected keyword argument 'aliased'"
2- I've tried to build two queries and use union_all but then I need to
specify all the columns and there are something like 40 columns to query.

How should I do to build this query ?

Cheers,

Gaston


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to