".M." <[EMAIL PROTECTED]> writes:

> I'm not sure I'm using the right phrase. I'm not talking about in a
> select clause more when defining the class. How do you define a class
> where instances refer to other instances of same class? I hadn't got as
> far as doing selects, catwalk is giving errors when I try and manage
> relationships. I've tried both related and multiple joins
>
> class Person(SQLObject):
>   name = StringCol(length=255)
>   friends = RelatedJoin('Person')

this is real close. the problem is that SQLObject's default conventions
for naming columns in the join table aren't quite smart enough. if you
do 

   Person._connection.debug = True

and then try to do the create, you'll see that it's trying to create a
join table like:

   CREATE TABLE person_person (
       person_id INT NOT NULL,
       person_id INT NOT NULL
   )

because it defaults to naming the columns after the entity that they
refer to. 

but you can override pretty much any of SQLObject's default behavior. so
something like this will work:

  class Person(SQLObject):
    name = StringCol()
    friends = RelatedJoin('Person',joinColumn='p1',otherColumn='p2',
                          addRemoveName='Friend')

then:

  p = Person(name='bob')
  p2 = Person(name='sue')
  p.addFriend(p2)

see: http://sqlobject.org/SQLObject.html#relatedjoin-many-to-many

for more details.

-- 
anders pearson : http://www.columbia.edu/~anders/
   C C N M T L : http://www.ccnmtl.columbia.edu/
        weblog : http://thraxil.org/

Attachment: pgpAJlBZ7CuAe.pgp
Description: PGP signature

Reply via email to