newbie question about relationships in model

18 views
Skip to first unread message

air_cooled

unread,
Feb 4, 2012, 2:58:49 AM2/4/12
to web2py-users
I've created a model in the GAE SQL tool - which was great, except it
didn't work in web2py. I just got errors.

So I created a model from the wizard to get going, but I've got some
strange behaviour around relationships.

I have a table 'labels' which is linked to a number of other tables.
A couple of these links work as you'd expect - in the edit screen you
see a drop list of the 'name' field from the relate table. For some
reason I can't fathom ONE of these tables ('winery') shows a text
field into which the ID of the related record has to be added. That
related table 'winery' is similar to the others that do work 'variety'
and 'retailcategory', and has a 'name' field with the same data type
as the others. These relationships are modelled:

Field('f_retailcategory', type='reference t_retailcategory',
label=T('Retailcategory')),
Field('f_winery', type='reference t_winery',
label=T('Winery')),
On searching the syntax is suggested as:

Field('f_winery_id', db.winery),

or


Field('f_winery_id', db.t_winery)

However adding these lines just causes it to blow up and show the
error:
<type 'exceptions.KeyError'> 'winery'

This is all a bit arcane. I can't understand why the GAE stuff
does'nt work after fixing all the parsing errors.
I've used PHP Cake a bit, so I get the concepts, but at this stage it
seems the documentation != practice.

Any tips?
thanks



Carlos Costa

unread,
Feb 4, 2012, 11:04:27 AM2/4/12
to web...@googlegroups.com
Is t_winery being created after this line?

2012/2/4 air_cooled <jam...@billson.com>:

--
Carlos J. Costa
Cientista da Computação
Esp. Gestão em Telecom

EL MELECH NEEMAN!
אָמֵן

air_cooled

unread,
Feb 4, 2012, 6:29:04 PM2/4/12
to web2py-users
So the order is important I take it, I'll check out the order on the
ones that work, and see if moving the definitions around helps.

However, surely this isn't going to be possible in every situation.
What if you have A -> B and B -> C and C -> A ? You can't satisfy all
these by putting them in order.
How do you get around this problem?
Reply all
Reply to author
Forward
0 new messages