If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


  • 0
    anthony  12 years ago

    Generally they are equivalent (behind the scenes, db.table gets converted to 'reference table'). The advantage of the 'reference table' version is that it can be used to refer to tables that have not yet been defined (including self references), whereas the db.table version obviously cannot be used this way.

    replies (3)
    • toomim 12 years ago

      You'd reference a table that hasn't been defined if the table occurs below the definition of the current one.

      Like:

      db.define_table('a', Field('b', 'references b')) db.define_table('b', ...)

      or you can do db.define_table('c', Field('c', 'references c'))

    • costarica 12 years ago
      • Does anyone know a use case of referencing tables that have not yet been defined? I am enjoying so much this framework that I need to know all the good stuff!
    • costarica 12 years ago
      • Why would I want to refererence tables that have not yet been defined (except for self references that I understand)? Thank you.

Commented on:

- What is the difference between 'reference table' and db.table when you are defining a foreign key?

 

Thanks.


Hosting graciously provided by:
Python Anywhere