samaras
samaras

Reputation: 344

Foreign Keys in web2py

I keep getting this error: 'DAL' object has no attribute 'event_instance'

it points to my db_agents file as the culprit on this line:

('event_instance_id', db.event_instance)

However if I move the definition of the event_instance table to that db_agents model file the error disappears, but I get a new one referering to another FKey in the event_instance tbl. Is there a way to avoid having all my db.define_tables in the same file, I would like to keep them separate.

Upvotes: 0

Views: 1111

Answers (1)

Anthony
Anthony

Reputation: 25536

You can do:

Field('event_instance_id', 'reference event_instance')

Using that alternative syntax, it is not necessary for the "event_instance" table to be defined already.

Also, note that model files are executed in alphabetical order, so your original code will work as long as the "event_instance" table is defined in a model file that comes earlier in alphabetical order.

Upvotes: 1

Related Questions