--- Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> On Sat, Feb 04, 2006 at 04:08:55PM -0800, Al > Pacifico wrote: > > I'm new to SQLObject... > > Welcome! > > > Expanding on the second inheritance scheme > advanced by > > Daniel Savard in > > http://sqlobject.org/Inheritance.html... > > > > Consider the following: > > > > from sqlobject.inheritance import > InheritableSQLObject > > class Person(InheritableSQLObject): > > firstName = StringCol() > > lastName = StringCol() > > > > class Employee(Person): > > _inheritable = False > > position = StringCol() > > > > class Consultant(Person): > > _inheritable = False > > assignment = StringCol() > > > > What code would I use to change an entry in the > person > > table from a consultant to an employee without > > altering the id field in the table (the oen > implied by > > use of the database)? > > This kind of inheritance is not your best friend > if you are going to > change the identity often. You can do > person.childName = "consultant" but > I'd like to recommend againts it and instead to > redesign the DB scheme. > Oleg- Your response doesn't surprise me, which is why I posted this in the first place. However, the problems with the first scheme outlined in that URL (see code snippet below) are that it takes away my ability to use polymorphism and that Person <-> Role is a one-to-one relationship for this application, so it doesn't add to this situation. from sqlobject import * from sqlobject.inheritance import InheritableSQLObject class Role(InheritableSQLObject): pass class Employee(Role): position = StringCol() class Consultant(Role): assignment = StringCol() class Person(SQLObject): firstName = StringCol() lastName = StringCol() roles = RelatedJoin("Role") So, I could swap Role and Person like this: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject class PersonData(InheritableSQLObject): firstName = StringCol() lastName = StringCol() class Role(SQLObject): details = RelatedJoin("PersonData") class Employee(Role): position = StringCol() class Consultant(Role): assignment = StringCol() This will give me polymorphism, i.e. ability to have employee.pay() and consultant.pay(). I'll have to write a little bit of code to get employee.lastName . Several questions: 1. Are the problems with person.childName = "Consultant" likely or severe enough to justify that? I don't anticipate this sort of change being made often, but it would be made sometimes... 2. If they do justify avoiding the previous scenario, is there a technique favored for obtaining some polymorphism in this situation? 3. If I didn't need to store any attributes that were Employee- or Consultant-specific, could I just use: from sqlobject import * class Person(SQLObject): firstName = StringCol() lastName = StringCol() class Employee(Person): pass class Consultant(Person): pass and end up with just a Person table, but still get the SQLObject functionality I want? Or is there some deep magic that will bite me if I do this? Thanks. -al __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
