[SQLObject] Allow NULLs in alternateID columns
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2007-07-23 09:19:47
|
Hello. I just met a situation in my program that some of my objects have an alternate ID, and some don't. But I found that SQLObject doesn't allow alternateID columns to contain NULLs. That strange; this is, after all, only a secondary ID. PostgreSQL explicitly allows NULLs in UNIQUE indices; MySQL allows them in non-BDB tables; SQLite doesn't say anything in the docs but allow NULLs anyway. I'd like to lift the restriction and allow NULLs in alternateID columns. Any idea, pro or contra suggestion? I asked Ian and he suggested that with this changes alternateID becomes not exactly an "alternate ID" because one cannot access all objects in the table with it, but he didn't oppose the change. He also suggested that I can do without the change by not using alternateID at all but instead using something like this: class fetcher(object): def __init__(self, fieldName): self.field_name = field_name def __get__(self, obj, type=None): if obj is not None: raise AttributeError def getter(value): values = type.selectBy(**{self.field_name: value}) return values[0] return getter class MyClass(SQLObject): byName = fetcher('name') Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |