On Wed, Dec 17, 2008 at 12:18:11PM +1100, Emmanuel Galanos wrote: > On Tue, Dec 16, 2008 at 02:54:26PM +0300, Oleg Broytmann wrote: > > On Tue, Dec 16, 2008 at 12:50:46PM +1100, Emmanuel Galanos wrote: > > > > > Unfortunately self.id is not available until after the object is > > > created. > > > > Certainly it is not available. But perhaps you want to set some values > > without touching the id? > > For the magic attribute, I need a unique identifier so that the > external data can reference the SQL object. The id column would appear > to be the obvious choice as is seen in the example at: > http://sqlobject.org/SQLObject.html#adding-magic-attributes-properties
Aha, ForeignKey; that's what I thought. > Ideally SQLObject would either determine the id before row insertion > (e.g. in PostgreSQL select nextval('blah_id_seq');) Impossible for other backends. It is also meaningless in SQL - an object cannot point to another object that has not been inserted. > or defer setting > of magic attributes until after the row is inserted. Wrong solution. Think about the example in the test_setters.py: class Test(SQLObject): firstName = StringCol() lastName = StringCol() def _set_name(self, v): firstName, lastName = v.split() self.firstName = firstName self.lastName = lastName def _get_name(self): return "%s %s" % (self.firstName, self.lastName) (I modified the example a bit) In it 'firstName' and 'lastName' are required attributes - they must be present at the creation time, hence a user must create an object as Test(name='first last'). The magic attributes must be passed before the object is created. The only time a magic attribute requires the object to be created already is when it wants to set another object pointing to this object. But SQLObject cannot recognize such situation, it is up to the user. Oleg. -- Oleg Broytmann http://phd.pp.ru/ p...@phd.pp.ru Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss