Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
well if only one relationship() has the foreign(Transaction.schema), then it doesn't conflict with anything else. I'd still take it off though for consistency On Mon, Dec 28, 2020, at 1:34 PM, sector119 wrote: > Thanks! > > service = relationship(*'Service'*, primaryjoin=*'and_(Service.schema

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread sector119
Thanks! service = relationship('Service', primaryjoin='and_(Service.schema == Transaction.schema, Service.id == foreign(Transaction.service_id))') eliminates the error But why I have no need to do the same with organization = relationship(...) ? Because Service model references Organization on

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
On Mon, Dec 28, 2020, at 12:37 PM, sector119 wrote: > Thank You, Mike, > > Do you mean that I have to remove all foreign() annotations from all my > relationships like this? > service = relationship(*'Service'*, primaryjoin=*'and_(Service.schema == > Transaction.schema, Service.id == Transacti

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread sector119
>>> is the above possible? or an error condition? I don't want to restrict that case >>> overall, if the plan is that "schema" will match across all the objects involved, and your application will make sure those are all set as needed, just >>> remove the foreign() annotation from the Transac

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread sector119
Thank You, Mike, Do you mean that I have to remove all foreign() annotations from all my relationships like this? service = relationship('Service', primaryjoin='and_(Service.schema == Transaction.schema, Service.id == Transaction.service_id)') organization = relationship('Organization', primary

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
by having foreign() on the Transaction.schema column, that means when you do this: t1 = Transaction() t1.service = some_service() the ORM is being instructed to copy some_service.schema over to t1.schema. Because "foreign" means "this is the column that mirrors the value of a canonical valu