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

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

 

Thanks.

Answers (1)

Comments (1)

  • Login to post



  • 0
    anthony 11 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 11 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 11 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 11 years ago
      • Why would I want to refererence tables that have not yet been defined (except for self references that I understand)? Thank you.

Related content


Hosting graciously provided by:
Python Anywhere