On Fri, Jul 31, 2009 at 09:36:19AM +0200, Tom Coetser wrote:
> I am trying to get my head around using a ManyToMany relation between tables 
> and hope to get some guidance here since the available docs are a bit sparse 
> on this (no offence - I know how difficult it is to keep docs up to 
> date :-) )

   The worst problem with ManyToMany is not documentation. The code was
added by the original author before he left the project, and I don't know if
the code by any means complete. I never used it. Consider it an unfinished
experimental code. Use RelatedJoin or SQLRelatedJoin instead.

> class Member(SQLObject):
>     name = StringCol(alternateID=True)
>     roles = ManyToMany('Role')
> 
> class Role(SQLObject):
>     name = StringCol(alternateID=True)
>     members = ManyToMany('Member')
> 
> I am testing with a SQLite backend for what it's worth.
> 
> Q1:
> Is there a way, by adding additional params to the ManyToMany(...) 
> declarations for example, to restrict the same role to be added multiple 
> times to the same member and vice versa?
> 
> Q2:
> Is there a way to restrict/cascade deletes of a role or member if that role 
> or 
> member has a link to the other?
> 
> Q3:
> When deleting a role or member using the .destroySelf() method, the link 
> record in the intermediate table is not deleted. Is there a standard way to 
> do this? I suppose an answer to Q2 will also address this.

   What you want could be achieved by a RelatedJoin with an explicit
intermediate table:
http://sqlobject.org/FAQ.html#how-can-i-define-my-own-intermediate-table-in-my-many-to-many-relationship
   In the intermediate table you can set cascade, add unique index, and so
on.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            p...@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to