On 7/23/15 2:18 PM, Rich Shepard wrote:
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?


conceptually not a big deal but API-wise has many mistakes. Sequences don't work with unicode, there is no "value" parameter, the table has no primary key.

----------
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

--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to