It has come up. "reference table" does not solve this problem. The
problem can be solved with the Table keyword but I think tables should
not refer to each other. Use a link table of set one of the references
to an int and use a validator to make it a reference.


On Aug 11, 9:56 am, Jonathan Lundell <[email protected]> wrote:
> On Aug 11, 2010, at 2:48 AM, Oatman wrote:
>
> > Jonathan,
>
> > Thanks very much for you pointing out the reference keyword, that
> > solves the problem for self-referencing tables, but do you know of a
> > solution to my two-tables-referencing-each-other problem? I admit my
> > simplistic alias example could be solved very elegantly by a self-
> > referencing table, but I'd like to know how to do it with two tables,
> > if I wanted.
>
> I'm pretty sure that the subject has come up on this list, but I don't recall 
> when. I'm hoping that someone (Massimo when he comes up for air, perhaps) 
> will chime in, and then we can add it to the manual section.
>
> I'm wondering, though, whether you can't use 'reference' in your first table 
> to refer to the second one.
>
>
>
> > Any thoughts? Thanks again
>
> > On Aug 10, 7:16 pm, Jonathan Lundell <[email protected]> wrote:
> >> On Aug 10, 2010, at 10:55 AM, Oatman wrote:
>
> >>> Hi all,
>
> >>> How do I create two tables that both refer to each other? Here's a
> >>> simple example:
>
> >>> db.define_table(
> >>>    'item',
> >>>    Field('current_alias', 'db.item_alias')
> >>>    )
>
> >>> db.define_table(
> >>>    'item_alias',
> >>>    Field('name'),
> >>>    Field('item', 'db.item')
> >>>    )
>
> >>> This throws
> >>>  "SyntaxError: Field: unknown field type: db.item_alias for
> >>> current_alias"
> >>> because they both need the other to be created first!
>
> >>> How can I create a simple relationship like this? Thanks in advance!
>
> >> If the answer to this question is 'reference' 
> >> <http://web2py.com/book/default/chapter/06?search=define_table#Self-Re...>,
> >>  perhaps we could add a line or three in the manual section to explicitly 
> >> mention forward references, and not only self references.

Reply via email to