Le vendredi 15 juin 2012 12:00:28 UTC+2, Thierry Florac a écrit : > > Hi, > > I'm using SQLAlchemy (0.7.4) with GeoAlchemy to map tables containing > geographic entities from a PostgreSQL/PostGIS database. > > As I have to handle data from several parts of the world, each part using > it's own geographic projection, my testing model which I'll try to describe > is based on: > - a parent class ("TestIMG"), containing common attributes and a shape in > "world-wide" WGS84 coordinates system > - for each projection system, a child class, inheriting from TestIMG and > containing only the shapes in the given projection system. > TestIMG can be seen as an abstract class; discrimination between child > classes is based on a common "SRID" attribute. > > I've mapped my classes as follow: > > class TestIMG(Base): > __tablename__ = 'test_img' > id = Column('id', Integer, primary_key=True) > data = Column('data', Unicode(20)) > wgs_shape = GeometryColumn('wgs_shape', Point(srid=4326)) > srid = Column('srid', Integer) > __mapper_args__ = { 'concrete': False, > 'polymorphic_on': srid } > > class TestIMG_france(TestIMG): > __tablename__ = 'test_img_france' > __mapper_args__ = { 'polymorphic_identity': 2154, > 'concrete': True } > id = Column('id', Integer, ForeignKey(TestIMG.id), primary_key=True) > shape = GeometryColumn('shape', Point(srid=2154)) > > class TestIMG_guyane(TestIMG): > __tablename__ = 'test_img_guyane' > __mapper_args__ = { 'polymorphic_identity': 32622, > 'concrete': True } > id = Column('id', Integer, ForeignKey(TestIMG.id), primary_key=True) > shape = GeometryColumn('shape', Point(srid=32622)) > > TestIMG_union = polymorphic_union({ 'test_img_france': > TestIMG_france.__table__, > 'test_img_guyane': > TestIMG_guyane.__table__ }, > 'projection', 'test_img') > > > When I make a query in a child class, everything is OK; but when I try to > query the main class, I get an error: > > >>> session.query(TestIMG).all() > > Traceback (most recent call last): > File "<console>", line 1, in <module> > File > "/var/local/eggs/SQLAlchemy-0.7.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", > > line 1947, in all > return list(self) > File > "/var/local/eggs/SQLAlchemy-0.7.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", > > line 2178, in instances > rows = [process[0](row, None) for row in fetch] > File > "/var/local/eggs/SQLAlchemy-0.7.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/mapper.py", > > line 2614, in _instance > return _instance(row, result) > File > "/var/local/eggs/SQLAlchemy-0.7.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/mapper.py", > > line 2627, in _instance > tuple([row[column] for column in pk_cols]) > File > "/var/local/eggs/SQLAlchemy-0.7.4-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", > > line 2654, in _key_fallback > expression._string_or_unprintable(key)) > NoSuchColumnError: "Could not locate column in row for column ' > test_img_france.id'" > > > I've tried to test several configurations but everything fails until now. > I'll also add that I **have to** use declarative form of SQLAlchemy, > because GeoAlchemy doesn't seem to handle anything else :-/ > > Any help would be greatly welcome ! > > Best regards, > Thierry >
Hum, hum...! In fact, it finally works, just by removing "concrete" argument from child classes mapper args... Sorry for the noise :-/ Regards, Thierry -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/4fFRswwC4o8J. 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.