On Apr 7, 2013, at 8:27 AM, Alexey Vihorev <[email protected]> wrote:
> Hi!
>
> I’ve got this setup:
>
> cs = "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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.