Goddamn this post helped me so much. I didn't realise I could mix 'n' 
match ActiveMapper and AssignMapper. So glad I didn't have to rewrite my 
entire model because I wanted a complicated join!

SqlAlchemy, I want your babies. And they will be beautiful.

-Rob

Mark Godfrey wrote:
> Chris,
> 
> I believe ActiveMapper alone won't do this, but you can leverage the
> rest of SQLAlchemy to do it.
> Below is an example of how I've managed to solve the same problem in my
> current project.
> 
> 
> # create a many to many join between TestObject and TestObject
> related_items_table = Table('related_items',
>     metadata,
>     Column('id', Integer, ForeignKey("test_object.id")),
>     Column('related_id', Integer, ForeignKey('test_object.id')))
> 
> # Our class definition
> class TestObject(ActiveMapper):
>     ## class mapping sets up the DB->Object map
>     class mapping:
>         __table__ = "test_object"
>         ## id stores the unique primary key for this product
>         id = column(Integer, primary_key=True)
>         ## name gives this product a name
>         name = column(Unicode(255))
>         ## description gives this product a description
>         description = column(Unicode(512))
> 
> # Then add a relation to TestObject's mapper instance
> TestObject.mapper.add_property('related', relation(TestObject,
>         secondary=related_items_table, uselist=True,
>         primaryjoin=TestObject.c.id==related_items_table.c.id,
> 
> secondaryjoin=TestObject.c.id==related_items_table.c.related_id,
>         foreignkey=TestObject.c.id))
> 
> 
> This will create a relation called TestObject.related which will
> contain a list of TestObject instances, which is what I think you are
> after.
> I hope this helps you solve your issue.
> 
> Regards,
> 
> Mark.
> 
> On Nov 6, 2:33 pm, "percious" <[EMAIL PROTECTED]> wrote:
>> Maybe this post wasn't clear.  Basically I have two foreign keys in a
>> table which point to the same *other* table.  Active mapper does not
>> seem to support this.  Anyone have an idea how I can get around the
>> problem?
>>
>> -chris
> 
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to