> > And I forgot to say that I would like to have a solution such that if > > new objects are added (i.e. new tables are added) that also can be > > commented on then I don't want to redesign anything. In the ideal case > > I would set something on the new table that indicates that this table > > (object) can be commented on and that should be it. > > Ah, then ignore the previous email. What you really need is a > ForeignKey pointing to your comment table in each of your other > objects. Then if you want an object to be able to have comments, just > add a "comment_id" column to that object/table. > > class FirstTable(SQLObject): > comment = ForeignKey("Comment") > > class SecondTable(SQLObject): > comment = ForeignKey("Comment") > > The difficult part becomes going back from the Comment object itself > to the object it is associated with. This would be pretty messy to do > purely with SQL and database schemas. But with python it is fairly > straight forward. Note: this also assumes a comment will only be > associated with one object in one other table. > > class Comment(SQLObject): > _objectTypes = [FirstTable, SecondTable] > def getOriginalObject(self): > for t in self._objectTypes: > for r in t.selectBy(commentID=self.id): > return r > raise KeyError, "This comment is not associated with anything!" > > You could come up with some SQLObject machinery that dynamically > creates the _objectTypes list, but the concept would be the same.
The problem with this approach is that a potentially large number of tables results in a potentially large number of queries so there might be a performance hit there. In addition, an object that can be commented on will typically have quite a few _get_XXXX type of methods such as date of last comment, total number of comments, etc, and with your approach all these methods have to be defined for every table which is quite redundant. Gregor, thanks for your link, I'll look into that example, looks like it is something I could use. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss