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 <mike...@zzzcomputing.com> 
> 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 sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to