You could always use custom _get_ and _set_ methods to enforce your
own compound keys. I've never tried it but it should be possible
(bearing in mind I'm writing this at 3am ;)
Using your example:
class Person(SQLObject):
name = StringCol(length=255)
dob = DateTimeCol()
@classmethod
def by_compound(self, name, dob):
# Returns one single select result.
# If the select below returns more than one result
# the setters aren't working.
return Person.select(AND(Person.q.name == name, Person.q.dob
== dob))[:1][0]
def _set_name(self, name):
if Person.select(AND(Person.q.name == name, Person.q.dob ==
self.dob)).count() > 0:
raise ValueError, "A Person with that compound key already exists"
else:
self._SO_set_name == name
def _set_dob(self, dob):
if Person.select(AND(Person.q.name == self.name, Person.q.dob
== dob)).count() > 0:
raise ValueError, "A Person with that compound key already exists"
else:
self._SO_set_dob == dob
The above may need some tweaking but I *think* it's about right...
you should be able to debug my early-morning-written-in-gmail code. :)
Also, there may be an exception that makes more sense than a
ValueError.
Lee
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---