[SQLObject] alternateMethodName and creating SQL
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Luke O. <lu...@me...> - 2003-03-12 21:34:29
|
Hello again - Col.alternateMethodName: apparently not implemented yet? I assume the implementation will look something like this (in the metaclass, while evaluating each Column object: I added it around line 195 in SQLObject.py): # If the column defines an alternateMethodName for retrieval # apply it to the object. if column.alternateMethodName: fun = eval('lambda cls, val: cls.select(cls.q.%s == val)[0]' % column.name) dict[column.alternateMethodName] = classmethod(fun) Of course, maybe part of the reason this hasn't been implemented yet is because the semantics are more difficult that the implementation: What does the user expect if there are really more than one returned by that query? What if there are none? If alternateID is set in the Column, is it SQLObject's responsibility to enforce uniqueness? Thoughts? (I'm using the code above until future notice. :) - Luke P.S. alternateMethodName in Col() expects a function called "prefix(str,str)"? I have no such function, so I ended up writing on that looks like: def prefix(pref, post): return "%s%s%s" % (pref, post[0].capitalize(), post[1:]) ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/ |