sqlalchemy - How to use the same field as foreign key for different tables? -


i have number of tables work source data, 1 per scientific area (biodata, geoldata, gravdata, magndata, , on). there table, main one, named product store info of each product id, project associated, etc. each product composed set of data. data records stored in disciplinar tables.

to store relation between product , data records of biodata example, i've done create many-to-many table named dataset_data. declaratives generated using sqlacodegen 'automatic model code generator sqlalchemy'.

t_dataset_data = table(     'dataset_data', metadata,     column('dataset_id', foreignkey(u'product.product_id'), primary_key=true, nullable=false),     column('data_id', foreignkey(u'biodata.id'), primary_key=true, nullable=false),     schema='public' )  class product(base):     __tablename__ = 'product'     __table_args__ = {u'schema': 'public'}      project_id = column(foreignkey(u'projects.p_id'), nullable=false)     datatable_id = column(foreignkey(u'datatables.id'), nullable=false)     product_id = column(integer, primary_key=true)      project = relationship(u'projects')     datatablename = relationship(u'datatables')      data = relationship(u'biodata', secondary=t_dataset_data) 

using sqlalchemy, when access product object, prod.data have access biodata records associated product. far good.

what need allow relation of product other data tables, ie, instead of using biodata, use data table geoldata example. note 1 product related 1 disciplinar table, ie, data records make product come same data table according datatable_id of product. need declare on t_dataset_data foreign key table (and not biodata) , consequently 'data' attribute of product source.

in short, need know if possible use different fk's in column 'data_id' of dataset_data, ie, how point different tables using column. if not possible, best approach achieve need?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -