From: Ian B. <ia...@co...> - 2004-04-22 15:59:55
|
Oleg Broytmann wrote: > Hello! > > I need a MultipleJoin, where ForeignKey is the id of the same table. > I cannot do it directly, because I cannot redeclare id column, so I > implemented it the following way: > > class Term(SQLObject): > translation = IntCol(default=None) # instead of MultipleJoin > > def _get_translation(self): > _translation = self._SO_get_translation() > if _translation is None: > return None > return self.select(self.q.id == _translation, orderBy="code") > > def _set_translation(self, codeObject): > if codeObject is not None: > codeObject = codeObject.id > self._SO_set_translation(codeObject) > > _doc_translation = "ID of the parent code term for this code" > > But this is ugly, and tiresome to reimplement every time I need such > a feature. How can I do it in a simpler way? Hmm... so this doesn't work? class Term(SQLObject): translation = ForeignKey('Term') Hmm... somewhere the terminology is getting all messed up, so I'm not sure how to follow your example. "translation" without your overrides should be the term translated. But then you want a backreference as well -- but you're naming the backreference the same as the forward reference. I think you need another accessor. There might still be a problem after you do that, but it's hard for me to understand this at all right now. Ian |