On 4/3/07, Sébastien LELONG <[EMAIL PROTECTED]> wrote: > > I dont have any code for this. Isn't that what a many-many relation is > > supposed to do? > many-to-many relation says "Article can have one or more ArticleRelated, and > ArticleRelated can have one or more Article". You just declare the > cardinality. You don't declare the direction. This is done while: > > c = ArticleRelatedArticle(article_id=a.id, related_id=b.id) > a.related.append(c) > > > > My problem is, if only one row is added, like 1=>2... > > A1.related will have A2 as an object, but A2.related is empty. how do > > i make it both ways?? > Well you should declare it in your code. Something like: > > c = ArticleRelatedArticle(article_id=a.id, related_id=b.id) # a => b > d = ArticleRelatedArticle(article_id=b.id, related_id=a.id) # b => a > a.related.append(c) > b.related.append(d) > >
Hi, This is causing very messy code though, especially if youa re deleteing an article. Here is now i have it now. The flush is needed, or else i get an AssertionError saying SA is trying to flush 0 into a primary_key. def removeRelated(self, article_id): rList = ArticleRelatedArticle.select( or_(and_(ArticleRelatedArticle.c.related_id==self.id, ArticleRelatedArticle.c.article_id==article_id), and_(ArticleRelatedArticle.c.related_id==article_id, ArticleRelatedArticle.c.article_id==self.id) ) ) for r in rList: r.delete() session.flush() And the article itself is removed like this: def remove(self): try: self.msgBoard[0].delete() except: pass self.removeRelated(self.id) self.delete() does this look ok to you guys? Or, can i do this in a better way? > > Hope it helps. > > Cheers. > > Seb > -- > Sébastien LELONG > http://www.sirloon.net > sebastien.lelong[at]sirloon.net > thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---