Thanks!

 

From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On
Behalf Of Michael Bayer
Sent: Sunday, April 07, 2013 5:46 PM
To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Self-referencing augmented class

 

 

On Apr 7, 2013, at 8:27 AM, Alexey Vihorev <viho...@gmail.com> wrote:





Hi!

 

I've got this setup:

 

cs = " <sqlite://:memory:> sqlite:///:memory:"
sa_engine = create_engine(cs)
 
Base = declarative_base()
 
class Person(Base):
 
    __abstract__ = True
 
    id = Column(Integer, primary_key=True)
    name = Column(String(30))
 
 
class Employee(Person):
 
    __tablename__ = 'employee'
    manager_id = Column(Integer, ForeignKey('employee.id'))
    manager = relationship('Employee', primaryjoin=(manager_id==Person.id),
remote_side=Person.id) #many-to-one
    comment = Column(String(100))
 
 
Base.metadata.drop_all(sa_engine)
Base.metadata.create_all(sa_engine)
 
Session = sessionmaker(bind=sa_engine)
s = Session()
e1 = Employee(name='John Smith') #sqlalchemy.exc.CompileError: Cannot
compile Column object until it's 'name' is assigned.

 

What gives? Thanks!

 

 

that Column object assigned to Person.id is not actually associated with any
Table; a copy of it has been made and associated with the "employee" table.
This hasn't happened yet when you declare your Employee class, so that
primaryjoin and remote_side needs to be as a string:

 

relationship("Employee", primaryjoin="Employee.manager_id==Employee.id",
remote_side="Employee.id")

 

 

 

 

 





 

 

 

 

-- 
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to  <mailto:sqlalchemy+unsubscr...@googlegroups.com>
sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to  <mailto:sqlalchemy@googlegroups.com>
sqlalchemy@googlegroups.com.
Visit this group at  <http://groups.google.com/group/sqlalchemy?hl=en>
http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit  <https://groups.google.com/groups/opt_out>
https://groups.google.com/groups/opt_out.
 
 

 

-- 
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to  <mailto:sqlalchemy+unsubscr...@googlegroups.com>
sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to  <mailto:sqlalchemy@googlegroups.com>
sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

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


Reply via email to