On Mon, 10 Apr 2006 17:39:45 +0200 Alberto Valverde <[EMAIL PROTECTED]> wrote:
>
> I've finally came up with this following your inspiration @ #1:
>
> class Article(SQLObject):
> title = StringCol()
> photos = MultipleJoin("ArticlePhoto", joinColumn="article_id")
>
> def _get_photos(self):
> return [ap.photo for ap in self._SO_get_photos()]
>
> def addPhoto(self, photo, sort_order=0):
> ArticlePhoto(article=self, photo=photo,
> sort_order=sort_order)
>
> def removePhoto(self, photo, sort_order=None):
> if sort_order is None:
> aps = ArticlePhoto.selectBy(article=self, photo=photo)
> else:
> aps = ArticlePhoto.selectBy(article=self,
> photo=photo,
> sort_order=sort_order)
> for ap in aps: ap.destroySelf()
>
> class Photo(SQLObject):
> title = StringCol()
> articles = MultipleJoin("ArticlePhoto", joinColumn="photo_id")
>
> def _get_articles(self):
> return [ap.article for ap in self._SO_get_articles()]
>
> def addArticle(self, article, sort_order=0):
> ArticlePhoto(article=article, photo=self,
> sort_order=sort_order)
>
> def removeArticle(self, article, sort_order=None):
> if sort_order is None:
> aps = ArticlePhoto.selectBy(article=article, photo=self)
> else:
> aps = ArticlePhoto.selectBy(article=article, photo=self,
> sort_order=sort_order)
> for ap in aps: ap.destroySelf()
>
>
> class ArticlePhoto(SQLObject):
> class sqlmeta:
> defaultOrder = ["sort_order"]
> article = ForeignKey("Article", cascade=True)
> photo = ForeignKey("Photo", cascade=True)
> sort_order = IntCol(default=0)
>
> This way it more resembles the current RelatedJoin interface (with
> addX, removeX, and Xs).
> Now I just need to find a way to factor this out for easy reuse, but
> that's my homework... :)
>
> Thanks for the head-start!
>
> Regards,
> Alberto
You might want to look at my ExtraRelatedJoin stuff. This is starting
to look a lot like it...
http://xentac.net/~jchu/blog/technology/sqlobject-extra-relatedjoins.html?showcomments=yes
Jason
signature.asc
Description: PGP signature

