Re: [SQLObject] How to provide default non-null values for foreign keys?

2008-07-23 Thread Luke Opperman
As Oleg notes, your default argument call to byName is evaluated at class creation time ie, before you've created the Sales Department record. In the same way, if you had: when = DateTimeCol(default=now()) the default would always be the value returned by now() at the time the class is imported

Re: [SQLObject] How to provide default non-null values for foreign keys?

2008-07-23 Thread Oleg Broytmann
On Wed, Jul 23, 2008 at 09:04:10PM +, Matthew Wilson wrote: > The byName lookup raises an SQLObjectNotFound exception. I don't see how you can misinterpret this. There is no 'Sales' department in the DB, so why do you expect SQLObject magically finds one?! .byName() is an "active" operat

Re: [SQLObject] How to provide default non-null values for foreign keys?

2008-07-23 Thread Matthew Wilson
On Wed 23 Jul 2008 04:01:19 PM EDT, Oleg Broytmann wrote: >In what way? For .byName() to work Department.name must be an > alternateID column (which implies uniqueness). >This works for me: > > class Department(SQLObject): >name = StringCol(default=None, alternateID=True) > > Department

Re: [SQLObject] How to provide default non-null values for foreign keys?

2008-07-23 Thread Oleg Broytmann
On Wed, Jul 23, 2008 at 07:50:47PM +, Matthew Wilson wrote: > I have an employees table and a departments table, and every employee > has a foreign key to the departments table. > > 99% of the time, new employees belong to one particular department, > "SALES". > > How can I make the SALES dep

[SQLObject] How to provide default non-null values for foreign keys?

2008-07-23 Thread Matthew Wilson
I have an employees table and a departments table, and every employee has a foreign key to the departments table. 99% of the time, new employees belong to one particular department, "SALES". How can I make the SALES department the default department for new employees? I tried this: class De