Originally posted here on June 4th, but no one responded. I'm now back on
this project and this should be the last table I need to add to the schema.
I would appreciate your review of the below class and whether it is good to
go or needs your modifications.

  Section 2.1.15 in the 1.0.8 manual describes building an association table
for many-to-many relationships. My application has a table that associates
multiple locations with multiple types of data collected. That is, each
location can have multiple types of data collected, and each data type can
be collected at multiple locations. There are other attributes associated
with each row. Will the following table declaration work? Or, do I separate
site and param into a separate table from the other columns?

----------
class Monitoring(Base):
    __table_name__ = 'monitoring'
    permit_nbr = Column(Unicode(24), ForeignKey('permits.nbr'))
    permit = relationship("Permits", back_populates = 'locations')
    data_type = Column(Unicode(16), CheckConstraint("data_type IN ('surface \
    water', 'ground water', 'air', 'benthos', 'fish', 'microbes', \
    'physical','weather')"))
    site = Column(Unicode(12), Sequence('location_seq'), nullable = False, \
    unique = True, ForeignKen('locations.site_id'))
    param = Column(Unicode(24), nullable = False, unique = True, ForeignKey(\
    'conditions.param_name'))
    mcl = Column(Float)
    monit_freq = Column(Unicode(12), value = 'Month', nullable = False, \
    CheckConstraint("monitor_freq IN ('Hour','Shift','Day','Week','2x month',\
    'Month','Quarter','Semi-Annual','Annual')"))
    rpt_freq = Column(Unicode(12), value = 'Month', nullable = False, \
    CheckConstraint("rpt_freq IN ('Hour','Shift','Day','Week','2x month',\
    'Month','Quarter','Semi-Annual','Annual')"))
    start_date = Column(Date, value = today, nullable = False)
    end_date = Column(Date)
    site = relationship("Locations", back_populates = 'monitoring')
    param = relationship("Conditions", back_populates = 'monitoring')
---------

Rich

Reply via email to