You can't. References are always by ID. You can use the IS_IN_DB to show 
the UUID instead of the ID but the database will continue to use the ID.

The presence of the UUID will be used by db.import_from_csv_file to fix 
references when importing records because it will build a temporary 
dictionary of {UUID:ID}.



On Friday, 27 July 2012 22:15:44 UTC-5, Mark Li wrote:
>
> I currently have 3 data tables setup, one is an intermediate table linking 
> a many to many relationship. I would like to use UUID as the reference ID, 
> so I insert the uuid into the intermediate table instead of the normal ID.
>
> However this doesn't work as expected, all the fields in the relational 
> data table are 0 after inserting the UUID.
>
> My db.py code below:
>
>
>
>
> db = DAL('sqlite://storage.sqlite')
>
> import uuid
>
> db.define_table('people',
> Field('uuid', length=64, default=uuid.uuid4(), notnull=True,writable=False
> , unique=True),
> Field('person'),
> Field('age'), format='%(person)s')
>
> db.define_table('foods',
> Field('uuid', length=64, default=uuid.uuid4(), notnull=True,writable=False
> , unique=True),
> Field('food'),
> Field('foodtype'), format='%(food)s')
>
> db.define_table('people_food',
> Field('person',db.people),
> Field('foods',db.foods))
>
>
> db.people_food.person.requires = IS_IN_DB(db,db.people.uuid,)
> db.people_food.foods.requires = IS_IN_DB(db,db.foods.uuid,)
>
>
> I am doing this so my references won't break, as the regular ID may change 
> if the database isn't empty. Any idea what I'm doing wrong here?
>
>

-- 



Reply via email to