OK, thanks you. I think it's a good idea to issue a warning in such cases.
Best regards Le samedi 2 janvier 2016 19:18:12 UTC+2, Michael Bayer a écrit : > > > > On 01/02/2016 11:38 AM, [email protected] <javascript:> wrote: > > Thank you. > > > > I hesitate between using this way, or explicitly specify the > relationship > > (is this a good idea? In my test I found 3 relations after prepare()) : > > it's fine to do that. Automap is still building its own relationship as > well which is why you end up with three of them. The > generate_relationship hook can be used to return None in those cases > where you don't want automap to generate a relationship: > > http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/automap.html#sqlalchemy.ext.automap.generate_relationship > > > > > > > | > > classThermostat(Base): > > __tablename__ ='thermostats' > > idbuiltin =Column(Integer,ForeignKey('device.id')) > > idthermometer =Column(Integer,ForeignKey('device.id')) > > thermometer =relationship(Dispositif,foreign_keys=idthermometer) > > builtin =relationship(Dispositif,foreign_keys=idbuiltin) > > | > > > > > > Another interesting point is how to detect this error to warn. I tried > > to use name_for_scalar_relationship() for that, but I don't kow how to > > get the relationships mapper. > > > > Best regards > > > > Le vendredi 1 janvier 2016 18:27:14 UTC+2, Michael Bayer a écrit : > > > > you need to use the name generation functions > > name_for_scalar_relationship() and/or > > name_for_collection_relationship() > > to produce different names in each case. The "constraint" parameter > > passed as we see in > > > http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/automap.html#handling-simple-naming-conflicts > > > < > http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/automap.html#handling-simple-naming-conflicts> > > > > > > is a ForeignKeyConstraint object, you can look inside of > > constraint.column_keys to see if it is ['idbuiltin'] or > > ['idthermometer'] and use that to generate a name. > > > > > > > > On 01/01/2016 04:16 AM, [email protected] <javascript:> wrote: > > > Hi all, > > > > > > I use automap with database reflection to import schema with > > sqlalchemy. > > > > > > In case I have two relationships on same foreign key in some > > table, only > > > one relationship is created by prepare(), the second one seems > > overwrited. > > > > > > My table looks like : > > > > > > | > > > Table('thermostat', > > > Base.metadata, > > > Column('id',INTEGER(),primary_key=True,nullable=False), > > > Column('idbuiltin',INTEGER(),ForeignKey('device.id > > <http://device.id>')), > > > Column('idthermometer',INTEGER(),ForeignKey('device.id > > <http://device.id>'))) > > > | > > > > > > How to control relationship creation to produce two distinct > > relationships ? > > > > > > Thank you and Happy New Year ! > > > > > > -- > > > 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 [email protected] <javascript:> > > > <mailto:[email protected] <javascript:> > <javascript:>>. > > > To post to this group, send email to [email protected] > > <javascript:> > > > <mailto:[email protected] <javascript:>>. > > > Visit this group at https://groups.google.com/group/sqlalchemy > > <https://groups.google.com/group/sqlalchemy>. > > > For more options, visit https://groups.google.com/d/optout > > <https://groups.google.com/d/optout>. > > > > -- > > 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 [email protected] <javascript:> > > <mailto:[email protected] <javascript:>>. > > To post to this group, send email to [email protected] > <javascript:> > > <mailto:[email protected] <javascript:>>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
