From 17b4de18d7d3eea88bb80fab855396ba8baa2b78 Mon Sep 17 00:00:00 2001 From: niphlod Date: Wed, 23 Oct 2013 21:30:44 +0200 Subject: [PATCH] allow unordered references (NOT recommended but still possible with limitations) --- gluon/dal.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gluon/dal.py b/gluon/dal.py index ca623c38..4f462cdc 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -864,7 +864,20 @@ class BaseAdapter(ConnectionPool): id_fieldname = table._id.name else: #make a guess id_fieldname = 'id' - real_referenced = db[referenced]._rname or db[referenced] + #gotcha: the referenced table must be defined before + #the referencing one to be able to create the table + #Also if it's not recommended, we can still support + #references to tablenames without rname to make + #migrations and model relationship work also if tables + #are not defined in order + if referenced == tablename: + real_referenced = db[referenced]._rname or db[referenced] + else: + real_referenced = ( + referenced in db and + (db[referenced]._rname or db[referenced]) + or referenced + ) ftype = types[field_type[:9]] % dict( index_name = field_name+'__idx', field_name = field_name,