Massimo, Denes,
thank you for your answers.

Before touching sql.py I have updated web2py to recent version(1.86.1)
and found that now references in KeyedTable do work now if string
notation is used like this:
    Field('model_id', 'reference car_models.model_id'),
After this
print( getattr(db.car_models,'_referenced_by'))
prints
[('cars', 'model_id')]

But the reference field is not presented as a dropdown list in
appadmin insert form:
http://localhost:8000/monicar_db_test/appadmin/insert/db/cars
Same for web2py created tables.

What is more important on KeyedTables you can delete row from a
referenced table. Constraint will not work if its not in the SQL
schema. You can't emulate constrains at DAL level.

Total:
database field references are useless for legacy databases as they
don't keep db integrity and they
don't help in rendering db to html.

References only matter when a table is created by web2py model. Then
the constraint will be put in to the SQL schema and work at SQL server
level.
I think this shell be in the docs.

Also IMHO it would be useful to add
ondelete = ''SET NULL"
constraint because
"CASCADE" kills information that shell be kept sometimes and
"NO ACTION" leaves references to deleted rows which need to be checked
with every select. Checking for NULL is simpler.

Reply via email to