thx, that is what i am wondering. they are one-to-one, maybe thats good enough for performance. so there's no easy way to do this.
On Wed, May 5, 2010 at 5:44 PM, Michael Bayer <[email protected]>wrote: > > I meant SQL. if you want to do polymorphic_on based on "a.type" it would > at the very least need to issue: > > SELECT c.*, a.type JOIN b ON c.b_id = b.id JOIN a ON b.a_id=a > > which is an expensive way to get to where you're going. It can be done of > course but not through relation(). > > > On May 5, 2010, at 5:36 PM, Timmy Chan wrote: > > "C"/"D" objects doesn't exist without "A" and "B"? maybe walk up the > graph: C.b.a.type > > im not sure this schema is sensible, if it's really bad, please advise, im > not attached to it! > > thax! > > On Wed, May 5, 2010 at 5:28 PM, Michael Bayer <[email protected]>wrote: > >> what query do you want to see when you select "C" and "D" objects ? >> >> >> >> On May 5, 2010, at 5:26 PM, Timmy Chan wrote: >> >> thx, is there a way to set that up, or something similar? >> >> after giving it thought, maybe polymorphic_on isn't what i need. in some >> sense, table "A" is similar to a generic container, and i want to constrain >> the type of "C" depending on "A"'s type column. is there a way to do this? >> >> On Wed, May 5, 2010 at 5:15 PM, Michael Bayer >> <[email protected]>wrote: >> >>> >>> On May 5, 2010, at 5:01 PM, Timmy Chan wrote: >>> >>> i have 4 tables, a, b, c, d. >>> >>> a has one-to-many relation with b, b with one-to-one relationship with c, >>> c is a polymorphic on a.type, with d being one of the polymorphic types. >>> >>> is there a way to implement this? >>> >>> details: >>> >>> this is what im trying to do in sqlalchemy: >>> >>> a = Table('a', metadata, >>> Column( 'id', Integer(), primary_key=True ), >>> Column( 'type', UnicodeText() ) ) >>> >>> b = Table('b', metadata, >>> Column( 'id', Integer(), primary_key=True ), >>> Column( 'a_id', Integer(), ForeignKey('a.id') ) ) >>> >>> c = Table('c', metadata, >>> Column( 'id', Integer(), primary_key=True ), >>> Column( 'b_id', Integer(), ForeignKey('b.id') ), >>> Column( 'class_id', Integer() ) ) >>> >>> d = Table('d', metadata, >>> Column( 'id', Integer(), primary_key=True ), >>> Column( 'data', Integer() ) >>> >>> mappers >>> >>> mapper( A, a ) >>> mapper( B, b, properties={'a': relationship( A, >>> uselist=False,backref='b', >>> 'c':relationship( C, uselist=False, backref='b') }) >>> >>> # Does a full join, does not work >>> mapper( C, c, polymorphic_on = a.c.type ) >>> mapper( D, d, inherits=C, polymorphic_identity = "D" ) >>> >>> >>> how can i change c to polymorphic on a, through the relationship? is >>> there a way to sort by d.data? (b-c/d is one-on-one). >>> >>> >>> this mapping is incorrect. mapper(C) cannot be polymorphic on a table >>> which is not part of its mapping, and mapper(C) does not contain an >>> "inherits" keyword to that of A. Usually the "polymorphic_on" setting is >>> on the base-most mapper in the hierarchy and its not clear here which mapper >>> you intend for that to be. >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<sqlalchemy%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/sqlalchemy?hl=en. >>> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<sqlalchemy%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<sqlalchemy%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
