Re: [sqlalchemy] One-to-many relationship between two subclasses with foreign key in parent classes

2019-03-24 Thread Jan Dalheimer
I guess the simplest solutions are often the best… Turns out this actually works flawlessly (from what I’ve been able to tell so far), I didn’t expect SQLAlchemy to be smart enough to figure it out so I never even tried it this simple… Thanks! > On 23 Mar 2019, at 20:04, Mike Bayer wrote: >

Re: [sqlalchemy] One-to-many relationship between two subclasses with foreign key in parent classes

2019-03-23 Thread Mike Bayer
On Sat, Mar 23, 2019 at 12:39 PM 02JanDal wrote: > > Hello, > > I have two simple inheritance trees using joined table inheritance, see code > below. In short, MembershipType inherits BaseShopItem and Membership inherits > TransactionItem and there is a one-to-many relationship between

[sqlalchemy] One-to-many relationship between two subclasses with foreign key in parent classes

2019-03-23 Thread 02JanDal
Hello, I have two simple inheritance trees using joined table inheritance, see code below. In short, MembershipType inherits BaseShopItem and Membership inherits TransactionItem and there is a one-to-many relationship between BaseShopItem and TransactionItem. This works well, but now I want

[sqlalchemy] one to many relationship

2014-07-31 Thread Rick Otten
I'm using sqlalchemy 0.8.7 on python 2.7.8. Here is my test case: #!/usr/bin/env python from sqlalchemy import Column, ForeignKey from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.dialects.postgresql import *

Re: [sqlalchemy] one to many relationship

2014-07-31 Thread Simon King
On 31 Jul 2014, at 21:34, Rick Otten rottenwindf...@gmail.com wrote: I'm using sqlalchemy 0.8.7 on python 2.7.8. Here is my test case: #!/usr/bin/env python from sqlalchemy import Column, ForeignKey from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative

Re: [sqlalchemy] one to many relationship

2014-07-31 Thread Rick Otten
That ForeignKey definition looks wrong - it should point at a column, not a class. I think you want: ForeignKey(parent.parent_id) Interesting, thanks, in the case where I use the same 'Base' for both classes, that solves it. In PostgreSQL the column definition isn't required if

[sqlalchemy] One to Many relationship of the same class as the parent class

2012-03-05 Thread Stefan
I have been struggeling for a few days with this now and trying to see if I maybe can get some help here. I'm using SQLAlchemy with Flask This is what I have tried so far: I got a user class defined like this: association_table = db.Table('association', db.Column('user_id', db.Integer,