On a second thought.... why is this not supported? Because I am not convinced this is a good idea.
If every record of table A only references one record of table B and vice versa then perhaps there should be only one table AB. If this is a one (A) to many (B) relation then A cannot contain a reference to B because would not be unique. If this is a many to many then there should be a link table. In your case: db.define_table('ports', Field('name','string') ) db.define_table('agents', field('name','string') ) db.define_table('port_agents', Field('port_id', db.ports), Field('agent_id',db.agents) ) It is also possible that I do not understand the problem you are working on and I am completely wrong. Massimo On Oct 8, 8:13 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > Thank you Markus, > > technically they are not allowed but you can do with a trick > > db.define_table('ports', > Field('name','string'), > Field('port_agent_id','integer') > ) > db.define_table('port_agents', > field('name','string', > Field('port_id', db.ports), > ) > db.ports.port_agent_id.requires=IS_IN_DB(db.'port_agents.id','%(name) > s') > db.port_agents.port_id.requires=IS_IN_DB(db.'ports.id','%(name)s') > > The port_agent_id reference would not be enforced by the database but > by web2py. On cascade delete would not work. Everything else would. > > On Oct 8, 3:59 am, Markus Schmitz <mschm...@soft-impact.com> wrote: > > > Hi everybody, > > > After evaluating quite a number of web frameworks, I ended up with > > web2py and frankly I am more than impressed. It rocks in many ways > > (could talk about it for some time really) and fits very close to my > > internal requirements. > > > But I am a newbee and I am running into newbee problems: > > > While creating the needed data model, I got stuck with a circular > > reference, which I can not resolve. This might be simply a problem > > with a bad design of my data model, but I will describe it anyway. > > > I have port_agents, which are assigned to specific ports. One port > > might have several port_agents. > > At the same time each port might have a preferred agent, so my model > > looks something like this: > > > db.define_table('ports', > > Field('name','string'), > > Field('port_agent_id','references port_agents') # this references > > ahead and does not work > > ) > > > db.define_table('port_agents', > > field('name','string', > > Field('port_id', db.ports), > > ) > > > How can this be done in web2py? > > > I could use a field 'is preferred agent' on the port agent, but then I > > have to build checks, that nobody else is a preferred agent for this > > port etc. > > > Any suggestions? > > > Regards > > > Markus --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---