Author: phd
Date: 2005-02-26 13:09:20 +0000 (Sat, 26 Feb 2005)
New Revision: 651
Modified:
trunk/SQLObject/docs/Inheritance.txt
trunk/SQLObject/sqlobject/inheritance/__init__.py
trunk/SQLObject/sqlobject/inheritance/tests/test_inheritance.py
trunk/SQLObject/sqlobject/main.py
Log:
InheritableSQLObject are now inheritable by default -
one does not need to set _inheritable = True.
Tests and documentation were updated.
Modified: trunk/SQLObject/docs/Inheritance.txt
===================================================================
--- trunk/SQLObject/docs/Inheritance.txt 2005-02-25 17:50:40 UTC (rev 650)
+++ trunk/SQLObject/docs/Inheritance.txt 2005-02-26 13:09:20 UTC (rev 651)
@@ -21,13 +21,13 @@
The following code::
- class Person(SQLObject):
- _inheritable = 1 # I want this class to be inherited
+ frim sqlobject.inheritance import InheritableSQLObject
+ class Person(InheritableSQLObject):
firstName = StringCol()
lastName = StringCol()
class Employee(Person):
- _inheritable = 0 # If I don't want this class to be inherited
+ _inheritable = False
position = StringCol()
will generate the following tables::
@@ -128,7 +128,7 @@
* You may not redefine columns in an inherited class (this
will raise an exception).
* If you don't want 'childName' columns in your last class (one that
- will never be inherited), you must set '_inheritable' to 0 in this
+ will never be inherited), you must set '_inheritable' to False in this
class.
* I made it because I needed to be able to have automatic
inheritance with linked table.
@@ -138,4 +138,4 @@
* Thanks to Ian Bicking for SQLObject, this is a wonderful python
module.
* If you have suggestion, bugs, or patch to this patch, you can
- contact me at <sqlobject xsoli.com>
+ contact SQLObject team: <sqlobject-discuss at lists.sourceforge.net>
Modified: trunk/SQLObject/sqlobject/inheritance/__init__.py
===================================================================
--- trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-02-25 17:50:40 UTC (rev 650)
+++ trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-02-26 13:09:20 UTC (rev 651)
@@ -65,6 +65,7 @@
class InheritableSQLObject(SQLObject):
+ _inheritable = True
SelectResultsClass = InheritableSelectResults
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
Modified: trunk/SQLObject/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- trunk/SQLObject/sqlobject/inheritance/tests/test_inheritance.py 2005-02-25 17:50:40 UTC (rev 650)
+++ trunk/SQLObject/sqlobject/inheritance/tests/test_inheritance.py 2005-02-26 13:09:20 UTC (rev 651)
@@ -8,12 +8,11 @@
class InherPerson(InheritableSQLObject):
- _inheritable = 1 # I want this class to be inherited
firstName = StringCol()
lastName = StringCol(alternateID=True)
class Employee(InherPerson):
- _inheritable = 0 # If I don't want this class to be inherited
+ _inheritable = False
position = StringCol()
def setup():
Modified: trunk/SQLObject/sqlobject/main.py
===================================================================
--- trunk/SQLObject/sqlobject/main.py 2005-02-25 17:50:40 UTC (rev 650)
+++ trunk/SQLObject/sqlobject/main.py 2005-02-26 13:09:20 UTC (rev 651)
@@ -396,10 +396,11 @@
#DSM: inheritable class. If so, we keep a link to our parent class.
cls._childClasses = {}
for _cls in cls.__bases__:
- if hasattr(_cls, '_inheritable') and _cls._inheritable:
- cls._parentClass = _cls
- cls._parent = None
- _cls._childClasses[cls.__name__] = cls
+ if hasattr(_cls, '_inheritable') and _cls._inheritable and \
+ _cls.__name__ <> "InheritableSQLObject":
+ cls._parentClass = _cls
+ cls._parent = None
+ _cls._childClasses[cls.__name__] = cls
#DSM: If this class is a child of a parent class, we need to do some
#DSM: attribute check and a a foreign key to the parent.
@@ -421,9 +422,11 @@
cls._columns = []
#DSM: If this is inheritable, add some default columns
# to be able to link to children
- if hasattr(cls, '_inheritable') and cls._inheritable:
- cls._columns.append(
- col.StringCol(name='childName',default=None))
+ if hasattr(cls, '_inheritable') and cls._inheritable and \
+ cls.__name__ <> "InheritableSQLObject":
+ cls._columns.append(
+ col.StringCol(name='childName', default=None)
+ )
cls._columns.extend(implicitColumns)
if not new_attrs.has_key('_joins'):
|