On Jul 29, 2010, at 5:00 PM, Kent Bower wrote:

> Right.  I understand.  Thanks for pointing that out, you are correct.
> 
> My bigger concern was getting the ArTranBase mapper correct.  Apparently 
> there is no need in this case to specify "with_polymorphic=" in the mapper.  
> Did I miss documentation on using 'polymorphic_union' without 
> "with_polymorphic="?  That seems to be working, I was just looking for 
> confirmation that this is a "supported" use-case.

that is probably correct.


> 
> 
> 
> On 7/29/2010 4:51 PM, Michael Bayer wrote:
>> What I meant was, if you want to say session.query(ArTranBase), which it 
>> appears that you do, then you are querying against ArTranBase.
>> 
>> Since it seems like you want the polymorphic_union here, when you query 
>> ArTranBase and you want it to eagerly load "trancode" and "paymenttype", it 
>> would need to have a relation() on the ArTranBase mapper so that it knows 
>> what to join.
>> 
>> 
>> 
>> 
>> On Jul 29, 2010, at 4:46 PM, Kent wrote:
>> 
>>   
>>> This seems to work, but I didn't find examples of this.  Does this
>>> look correct (assuming there is no parent table in the database and
>>> all I really want is 2 'normal' mappers and a 3rd that performs a
>>> polymorphoric_union)?
>>> 
>>> ==========================================
>>> 
>>> artran_union = polymorphic_union({
>>>        'artran': artrans_table,
>>>        'archive': artransarchive_table
>>>    }, 'type', 'artran_union')
>>> 
>>> artranbase_mapper = mapper(ArTranBase, artran_union,
>>>    polymorphic_on=artran_union.c.type)
>>> 
>>> 
>>> # ---------------------------- ArTran
>>> --------------------------------------- #
>>> mapper(ArTran, artrans_table, inherits=artranbase_mapper,
>>>    concrete=True, polymorphic_identity='artran',
>>>    properties={'trancode': relation(TranCode,
>>>                    cascade='refresh-expire,expunge', lazy=False),
>>>                'paymenttype': relation(PaymentType,
>>>                    cascade='refresh-expire,expunge', lazy=False)}
>>>    )
>>> 
>>> 
>>> # ---------------------------- ArTranArchive
>>> --------------------------------------- #
>>> mapper(ArTranArchive, artransarchive_table,
>>> inherits=artranbase_mapper,
>>>    concrete=True, polymorphic_identity='archive',
>>>    properties={'trancode': relation(TranCode,
>>>                    cascade='refresh-expire,expunge', lazy=False),
>>>                'paymenttype': relation(PaymentType,
>>>                    cascade='refresh-expire,expunge', lazy=False)}
>>>    )
>>> 
>>> 
>>> 
>>> On Jul 29, 4:20 pm, Kent Bower<k...@retailarchitects.com>  wrote:
>>>     
>>>> No, in fact, there is no ArTranBase table at all.
>>>> 
>>>> If I remove concrete inheritance, how do I issue a UNION of the two
>>>> tables and have the objects polymorphically loaded?
>>>> 
>>>> On 7/29/2010 4:18 PM, Michael Bayer wrote:
>>>> 
>>>>       
>>>>> On Jul 29, 2010, at 2:31 PM, Kent wrote:
>>>>>         
>>>>       
>>>>>> I'm getting a messy error that could be a bug, but is very likely
>>>>>> related to my setup of a set of 2 polymorphic classes I am attempting
>>>>>> to map.
>>>>>>           
>>>>       
>>>>>> One entity is a "transaction" and the other is a "transaction_archive"
>>>>>> record.  The table structure is therefore very similar for both tables
>>>>>> and it seems to fit Concrete Table Inheritance, except there is no
>>>>>> 'parent' entity.  Rather, they are sister tables.
>>>>>>           
>>>>       
>>>>>> What I have mostly works until I get into loading this union as a
>>>>>> relation to another table... then I'm having problems.
>>>>>>           
>>>>       
>>>>>> I couldn't clearly see the "correct" way to set up this when there is
>>>>>> no real inheritance, but rather sister entities.
>>>>>>           
>>>>       
>>>>>> Can you suggest how to correctly map these 2 tables?
>>>>>>           
>>>>       
>>>>> it looks fine to me except you're asking for eager loading, and if you're 
>>>>> querying from the ArTranBase you'd need to specify relationship() at that 
>>>>> level (as well as on each child).  Example 
>>>>> athttp://www.sqlalchemy.org/docs/mappers.html#using-relationships-with-....
>>>>>         
>>>>       
>>>>> OTOH if you are not querying from ArTranBase, remove the usage of 
>>>>> concrete inheritance altogether.
>>>>>         
>>>>       
>>>>>> ================================================
>>>>>> artran_union = polymorphic_union({
>>>>>>         'artran': artrans_table,
>>>>>>         'archive': artransarchive_table
>>>>>>     }, 'type', 'artran_union')
>>>>>>           
>>>>       
>>>>>> artranbase_mapper = mapper(ArTranBase, artran_union,
>>>>>> with_polymorphic=('*', artran_union),
>>>>>>     polymorphic_on=artran_union.c.type,
>>>>>> polymorphic_identity='ignored')
>>>>>>           
>>>>       
>>>>>> # ---------------------------- ArTran
>>>>>> --------------------------------------- #
>>>>>> mapper(ArTran, artrans_table, inherits=artranbase_mapper,
>>>>>>     concrete=True, polymorphic_identity='artran',
>>>>>>     properties={'trancode': relation(TranCode,
>>>>>>                     cascade='refresh-expire,expunge', lazy=False),
>>>>>>                 'paymenttype': relation(PaymentType,
>>>>>>                     cascade='refresh-expire,expunge', lazy=False)}
>>>>>>     )
>>>>>>           
>>>>       
>>>>>> # ---------------------------- ArTranArchive
>>>>>> --------------------------------------- #
>>>>>> mapper(ArTranArchive, artransarchive_table,
>>>>>> inherits=artranbase_mapper,
>>>>>>     concrete=True, polymorphic_identity='archive',
>>>>>>     properties={'trancode': relation(TranCode,
>>>>>>                     cascade='refresh-expire,expunge', lazy=False),
>>>>>>                 'paymenttype': relation(PaymentType,
>>>>>>                     cascade='refresh-expire,expunge', lazy=False)}
>>>>>>     )
>>>>>>           
>>>>       
>>>>>> Thanks in advance.
>>>>>>           
>>>>       
>>>>>> --
>>>>>> 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 
>>>>>> athttp://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.
> 

-- 
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