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/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to