-----------------------
class BaseClass(InheritableSQLObject):
reference = ForeignKey('RefClass', default=None)
class OtherClass(BaseClass):
reference = ForeignKey('RefClass', default=None)
class RefClass(SQLObject):
base_classes = MultipleJoin('BaseClass',joinColumn='reference_id')
other_classes = MultipleJoin('OtherClass',joinColumn='reference_id')
----------------------
the problem is that instances of OtherClass are showing up in
RefClass.base_classes and NOT in RefClass.other_classes, as they
should.
Any ideas?
I'm not really sure but I think you shouldn't provide the reference twice.
It's enough to provide it on the BaseClass only.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
.------------------------------------------------------------------------,
\ GPG: 5F5A8D05 // F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05 /
'--------------------------------------------------------------------'
Bald men with no jobs and no money who live with their parents don't approach
strange women.
-- George Constanza
You can't do that this way. reference can only be used once. Rename to e.g.
other_class_reference
and then create a property on OtherClass with name reference, that does the
getting and setting. Maybe that helps, I didn't test it though.
Diez
------------------
class BaseClass(InheritableSQLObject):
base_reference = ForeignKey('RefClass', default=None)
def _get_reference(self):
return self.base_reference
def _set_reference(self,value):
self.base_reference = value
class OtherClass(BaseClass):
other_reference = ForeignKey('RefClass', default=None)
def _get_reference(self):
return self.other_reference
def _set_reference(self,value):
self.other_reference = value
class RefClass(SQLObject):
base_classes =
MultipleJoin('BaseClass',joinColumn='base_reference_id')
other_classes =
MultipleJoin('OtherClass',joinColumn='other_reference_id')
-------------------
this produces the correct behavior if instances of OtherClass are
created without the reference parameter and then the reference
parameter is set after instantiation, but the problem still exists if
you do something like this:
ref=RefClass()
other=OtherClass(reference=ref)
It doesn't seem to use the overloaded get and set methods when creating
the object.
You can override the _create-method in both classes and map reference to the
respective property that is really needed.
Diez
Here's my code for anyone having similar issues:
------------------------
class BaseClass(InheritableSQLObject):
base_reference = ForeignKey('RefClass', default=None)
def _get_reference(self):
return self.base_reference
def _set_reference(self,value):
self.base_reference = value
def _create(self,id,reference=None,**kargs):
super(BaseClass,self)._create(id,**kargs)
if reference:
self.reference = reference
class OtherClass(BaseClass):
other_reference = ForeignKey('RefClass', default=None)
def _get_reference(self):
return self.other_reference
def _set_reference(self,value):
self.other_reference = value
def _create(self,id,reference=None,**kargs):
super(OtherClass,self)._create(id,**kargs)
if reference:
self.reference = reference
class RefClass(SQLObject):
base_classes =
MultipleJoin('BaseClass',joinColumn='base_reference_id')
other_classes =
MultipleJoin('OtherClass',joinColumn='other_reference_id')
--------------------------