ticket #1892 wasn't finished for declarative
Issue #2491
resolved
only in 0.8. foreign() and remote() annotations also broken.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base= declarative_base()
class CommonObject(Base):
__tablename__ = "objects"
id = Column("objid", Integer, primary_key=True)
objname = Column(String(32))
class Container(CommonObject):
__tablename__ = 'containers'
id = Column("objid", Integer, ForeignKey("objects.objid"), primary_key=True)
class GoodsPlacement(Container):
__tablename__ = "goods_placements"
id = Column("objid", Integer, ForeignKey("containers.objid"), primary_key=True)
class Departure(CommonObject):
__tablename__ = "departures"
id = Column(Integer, ForeignKey("objects.objid"), primary_key=True)
content_id = Column(Integer, ForeignKey("goods_placements.objid"))
status_id = Column(Integer)
content = relationship("GoodsPlacement",
primaryjoin="Departure.content_id==GoodsPlacement.id",
foreign_keys=[content_id](content_id),
#lazy='joined',
backref="departures"
)
the query is broken also, separate issue:
session = Session()
print session.query(GoodsPlacement).filter(~GoodsPlacement.departures.any(Departure.status_id < 2))
Comments (8)
-
reporter -
reporter (also the query from
#2492works here likely due to the recent enhancements to any()) -
reporter OK further analysis suggests this might be mapping setting up the wrong columns:
from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base= declarative_base() class CommonObject(Base): __tablename__ = "objects" id = Column("objid", Integer, primary_key=True) objname = Column(String(32)) class GoodsPlacement(CommonObject): __tablename__ = "goods_placements" id = Column("objid", Integer, ForeignKey("objects.objid"), primary_key=True) # fails assert GoodsPlacement.id.property.columns[0](0) is Base.metadata.tables['goods_placements']('goods_placements').c.objid
specifically its that we failed to make a required adjustment called for by
#1892:--- a/lib/sqlalchemy/ext/declarative.py Wed May 23 12:23:56 2012 -0400 +++ b/lib/sqlalchemy/ext/declarative.py Wed May 23 12:30:24 2012 -0400 @@ -1388,11 +1388,9 @@ if k in inherited_mapper._props: p = inherited_mapper._props[k](k) if isinstance(p, ColumnProperty): - # note here we place the superclass column - # first. this corresponds to the - # append() in mapper._configure_property(). - # change this ordering when we do #1892 - properties[k](k) = p.columns + [col](col) + # note here we place the subclass column + # first. See #1892 for background. + properties[k](k) = [col](col) + p.columns result_mapper_args = mapper_args.copy() result_mapper_args['properties']('properties') = properties
-
reporter - changed milestone to 0.7.8
-
reporter - changed title to ticket #1892 wasn't finished for declarative
-
reporter - changed status to resolved
-
reporter -
reporter - removed milestone
Removing milestone: 0.7.8 (automated comment)
- Log in to comment
if you take out the primaryjoin, it works:
but this makes absolutely no sense.