|
1 | | -from sqlalchemy import BigInteger, Column, Date, DateTime, Float, ForeignKey, Integer, String, Boolean, BLOB |
| 1 | +from sqlalchemy import BigInteger, Column, Date, DateTime, Float, ForeignKey, Integer, String, Boolean, BLOB, case |
2 | 2 | from sqlalchemy.orm import relationship |
3 | 3 | from sqlalchemy.dialects import postgresql, mysql, sqlite |
4 | | -# Should not be importing anything from a specific dialect |
5 | | -# from sqlalchemy.dialects.mssql.base import BIT |
| 4 | + |
6 | 5 |
|
7 | 6 | from geoalchemy import GeometryDDL, GeometryColumn |
8 | 7 | from geoalchemy.geometry import Geometry |
@@ -280,11 +279,17 @@ class SamplingFeatures(Base): |
280 | 279 | FeatureGeometryWKT = Column('featuregeometrywkt', String(50)) |
281 | 280 | # FeatureGeometry = Column('featuregeometry', BLOB) # custom geometry queries |
282 | 281 | __mapper_args__ = { |
| 282 | + # 'polymorphic_on': SamplingFeatureTypeCV, |
| 283 | + "polymorphic_on":case([ |
| 284 | + (SamplingFeatureTypeCV == "Specimen", "Specimen"), |
| 285 | + (SamplingFeatureTypeCV == "Site", "Site"), |
| 286 | + ], else_="samplingfeatures"), |
283 | 287 | 'polymorphic_identity':'samplingfeatures', |
284 | | - 'polymorphic_on': SamplingFeatureTypeCV, |
285 | | - 'with_polymorphic':'*' |
| 288 | + # 'with_polymorphic':'*' |
286 | 289 | } |
287 | 290 |
|
| 291 | + |
| 292 | + |
288 | 293 | def shape(self): |
289 | 294 | """ |
290 | 295 | Method name based on shapely shapely.geometry.shape() function. |
@@ -466,9 +471,21 @@ class Results(Base): |
466 | 471 | VariableObj = relationship(Variables) |
467 | 472 |
|
468 | 473 | __mapper_args__ = { |
469 | | - 'polymorphic_on':ResultTypeCV, |
| 474 | + # 'polymorphic_on':ResultTypeCV, |
| 475 | + "polymorphic_on":case([ |
| 476 | + (ResultTypeCV == "Point coverage", "Point coverage"), |
| 477 | + (ResultTypeCV == "Profile Coverage", "Profile Coverage"), |
| 478 | + (ResultTypeCV == "Category coverage", "Category coverage"), |
| 479 | + (ResultTypeCV == "Transect Coverage", "Transect Coverage"), |
| 480 | + (ResultTypeCV == "Spectra coverage", "Spectra coverage"), |
| 481 | + (ResultTypeCV == "Time series coverage", "Time series coverage"), |
| 482 | + (ResultTypeCV == "Section coverage", "Section coverage"), |
| 483 | + (ResultTypeCV == "Profile Coverage", "Profile Coverage"), |
| 484 | + (ResultTypeCV == "Trajectory coverage", "Trajectory coverage"), |
| 485 | + (ResultTypeCV == "Measurement", "Measurement"), |
| 486 | + ], else_="results"), |
470 | 487 | 'polymorphic_identity':'results', |
471 | | - 'with_polymorphic':'*' |
| 488 | + # 'with_polymorphic':'*' |
472 | 489 | } |
473 | 490 |
|
474 | 491 | def __repr__(self): |
@@ -738,7 +755,9 @@ class Specimens(SamplingFeatures): |
738 | 755 | __mapper_args__ = { |
739 | 756 | 'polymorphic_identity':'Specimen', |
740 | 757 | } |
741 | | - |
| 758 | + def __repr__(self): |
| 759 | + return "<Specimens('%s', '%s', '%s', '%s',)>" \ |
| 760 | + % (self.SamplingFeatureID, self.SamplingFeatureCode, self.SpecimenTypeCV,self.SamplingFeatureCode) |
742 | 761 |
|
743 | 762 | class SpatialOffsets(Base): |
744 | 763 | __tablename__ = u'spatialoffsets' |
|
0 commit comments