On Wed, Jul 23, 2008 at 07:50:47PM +0000, 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 department the default department for new
> employees?
> 
> I tried this:
> 
>     class Department(SQLObject):
>         name = UnicodeCol(alternateID=True)
> 
>     class Employee(SQLObject):
>         user_name = UnicodeCol(alternateID=True)
>         department = ForeignKey(default=Department.byName("SALES")
> 
> And it failed.

   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.createTable()

Department(name='Directorat')
Department(name='Sales')

class Employee(SQLObject):
   name = StringCol(default=None)
   department = ForeignKey('Department', default=Department.byName('Sales'))

Employee.createTable()
Employee(name='slave')

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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to