From: Ian B. <ia...@co...> - 2003-05-07 01:55:40
|
On Tue, 2003-05-06 at 17:54, Ian Bicking wrote: > I like the idea of subclasses (like Employee) sharing a primary key with > their superclass, and potentially the superclass having references as to > which subclass they belong to (from that modeling paper Luke referenced > a while ago). But I'm not sure how best to actually implement that -- > both in the database/SQL, and in the Python side. So that's a future > goal, and wouldn't replace this current kind of inheritance (just > provide an alternative). Hmmm... a thought on the interface for this sort of inheritance: class Person(SQLObject): name = StringCol(length=20) class Employee(SubSQLObject): salary = CurrencyCol() Then, would you have Person(1).employee.salary? Or Person(1).salary (AttributeError if it's not an employee, or None?). This way the superclass knows about the subclasses, as it has to eventually. It's more composition than inheritance, but I think that actually represents the reality of the database better anyway... it's a funny sort of composition more than it is inheritance (but it can still be used like inheritance). As with other declarations, you could do: class Employee(SubSQLObject): ... Person.addSubSQLObject(Employee) Whether SubSQLObject would be a placeholder/factory (like Col has become), or a real class (subclass of SQLObject and MetaSQLObject, probably), I'm not sure. Thoughts? Ian |