no problem, that test uncovered a place I could ratchet things down  
some more so everybody wins.   you want rev 2383.

On Mar 5, 2007, at 3:09 PM, Pete Taylor wrote:

> yessir, when using selectables i always just use  
> selectobj.c.colname...
>
> i've attached a quick test case, and it throws the same error that my
> live code does, so it at least proves i can break things the same way
> twice :D  i wouldn't be surprised if it's something easy that i'm just
> doing wrong, but here it is all the same.
>
> the test case relation for lineItems is the most bare-bones version of
> the one's i've tried, but this is the first one I tried...  it merely
> substitutes foreign_keys for where, pre-2309, had foreignkey.
>
> Thanks for looking!
> Pete
>
> On 3/5/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>>
>> please forward an runnable example test case, preferably a single
>> file with <200 lines if possible.
>>
>> you're also making usage of Column instances directly off the
>> selectable youre mapping, right ?
>>
>>
>> On Mar 5, 2007, at 1:55 PM, Pete Taylor wrote:
>>
>>>
>>> in regard to post-2309 revisions and the foreignkey keyword
>>> deprecation...
>>>
>>> I know this conversation seems to have terminated as of 2/21, but  
>>> it's
>>> the only thread that was tracing through a problem i'm having.  I'm
>>> certain my problem is just one of my own lack of understanding on  
>>> how
>>> to use foreign_keys now, but I'll lay it out there...
>>>
>>> I have a legacy table that, in effect, maps to two classes.  A
>>> container-style class and a line items class, which for convenience
>>> we'll just call Container and LineItem.  A Container has_many
>>> LineItem, as you might imagine.  The issue, however, is that the
>>> Container class is mapped against a select statement from that  
>>> table,
>>> not the table directly, while the LineItem class is mapped  
>>> against the
>>> table, largely because there's an incrementing LineItem id that's a
>>> primary key on the table, but has no meaning to the Container.
>>>
>>> before 2309, I was able to map the lineItem relationship back to the
>>> container class using an explicit primary join and a foreignkey
>>> statement.
>>>
>>> I've read through the self-referential example rather a lot, and the
>>> two mailing list threads, and have tried all the combinations and
>>> permutations of primaryjoin, foreign_keys, and remote_side that I  
>>> can
>>> think of (obviously not all of them or it would have worked ;) ),  
>>> from
>>> the mappers and relationships on both classes, and I can't seem to
>>> figure out the right way to make it work.  I can send along a
>>> simplified mockup of the relationships and what I've got  
>>> currently if
>>> anyone has time to take a look, but I may in fact just be heading  
>>> the
>>> wrong direction...
>>>
>>> Any help would be greatly appreciated!
>>> Pete Taylor
>>>
>>> --
>>> "All guilt is relative, loyalty counts, and never let your  
>>> conscience
>>> be your guide."
>>>   - Lucas Buck, American Gothic
>>>
>>>>
>>
>>
>>>
>>
>
>
> -- 
> "All guilt is relative, loyalty counts, and never let your conscience
> be your guide."
>   - Lucas Buck, American Gothic
>
> >
> #!/usr/bin/env python
>
> import datetime
> from sqlalchemy import *
>
> db = create_engine('sqlite:///:memory:')
> metadata = BoundMetaData(db)
>
> class Container(object): pass
> class LineItem(object): pass
>
> items = Table('items', metadata,
>     Column('item_policy_num', String(10), primary_key=True,  
> key='policyNum'),
>     Column('item_policy_eff_date', DateTime, primary_key=True,  
> key='policyEffDate'),
>     Column('item_type', String(20), primary_key=True, key='type'),
>     Column('item_id', Integer, primary_key=True, key='id'),
> )
>
>
> container_select = select(
>     [items.c.policyNum, items.c.policyEffDate, items.c.type],
>     distinct=True,
>     ).alias('container_select')
>
> LineItem.mapper = mapper(LineItem, items)
>
> Container.mapper = mapper(Container, container_select, order_by=asc 
> (container_select.c.item_type), properties=dict(
>     lineItems = relation(LineItem, lazy=False, cascade='all, delete- 
> orphan', order_by=asc(items.c.type),
>         primaryjoin=and_(
>             container_select.c.item_policy_num==items.c.policyNum,
>              
> container_select.c.item_policy_eff_date==items.c.policyEffDate,
>             container_select.c.item_type==items.c.type
>         ),
>         foreign_keys=[
>             items.c.policyNum,
>             items.c.policyEffDate,
>             items.c.type,
>         ],
>     )
> ))
>
> def main():
>     metadata.create_all()
>     session = create_session()
>     con = Container()
>     con.policyNum = "9999999999"
>     con.policyEffDate = datetime.date.today()
>     con.type = "TESTER"
>     session.save(con)
>     for i in range(0, 10):
>         li = LineItem()
>         li.id = i
>         con.lineItems.append(li)
>         session.save(li)
>     session.flush()
>     session.clear()
>     con = session.query(Container).selectfirst()
>     print "DEBUG: con has %s line items" % len(con.lineItems)
>
> if __name__ == "__main__":
>     main()


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

Reply via email to