On Jul 3, 12:14 pm, Rick Hultgren <[email protected]> wrote:
> Thanks for the link. My actual problem is more complicated than the

...a sure sign you need to simplify - either the way you look at it,
or the way you represent ..

(it isn't clear to me what you are trying to implement --- I do see a
struggle w/ implementation concept; maybe you can start with a clear
description?)

> example I gave. I realize that I need to link a field to a table that
> isn't initiated yet (item2):
>
>         objects = ['substance', 'process', 'condition', 'locus']
>         linksubobjects = ['locus', 'before', 'after']
>         unlinksubobjects = ['name', 'main_name']
>         for object in objects:
>                 for item1 in linksubobjects+unlinksubobjects:
>                         for item2 in objects:
>                                 fields=[Field(item1, 'reference item2')]
>                                 db.define_table(object,*fields)
>
> I suppose the solution would be to initiate the table names and then
> add the fields either in db.py, or in the controller file. But I have
> no idea how to do this.


You seem to be trying to write (effectively) this:

db.define_table( 'substance',
  Field( 'locus_name',  db.substance),
  Field( 'locus_name',  db.process),
  Field( 'locus_name',  db.condition),
  Field( 'locus_name',  db.locus),
  Field( 'locus_main_name',  db.substance),
  Field( 'locus_main_name',  db.process),
  Field( 'locus_main_name',  db.condition),
  Field( 'locus_main_name',  db.locus),
  Field( 'locus_name',  db.substance),
  Field( 'before_name',  db.process),
  Field( 'before_name',  db.condition),
  Field( 'before_name',  db.locus),
  Field( 'before_main_name',  db.substance),
  Field( 'before_main_name',  db.process),
  Field( 'before_main_name',  db.condition),
  Field( 'before_main_name',  db.locus),
....


Ignoring the syntactic errors (it makes no sense to have multiple
fields with the same name, or referring to multiple tables).... at a
logical level, this doesn't make sense (at best is lacking clarity).

It seems (also) that you are in need of some basic prerequisites
(i.e.  table references are to table rows, by way of keys - 'id' field
in web2py nomenclature, primary key in general terminology) - you can
help yourself cement this concept by naming all your reference fields
ending in "..._id";  this should help you:  "do I mean 'before_name',
or the name in the before_id  record? What to I really need to
reference?"

Perhaps using a data model would help you struggle with this at the
appropriate level (it does not seem you are ready to start
implementing this in web2py, or any implementation yet).

Try laying out what you are trying to think about - this is a web-
based modeling tool:   http://code.google.com/p/wwwsqldesigner/  (you
can follow / use the demo installation).

Draw the relationships, clarify, organize your thoughts first.

Regards,
- Yarko


>
> On 7/3/10, Yarko Tymciurak <[email protected]> wrote:
>
> > The online book has a fairly useful search;
>
> > For your question, see:
> >http://web2py.com/book/default/section/6/13
>
> > Regards,
> > - Yarko
>
> > On Jul 3, 8:45 am, Rick <[email protected]> wrote:
> >> Hi,
>
> >> I would like to link a table to its own model like this:
>
> >>         db.define_table('person',
> >>                 Field('name'),
> >>                 Field('child', db.person))
>
> >> I understand that I should first initiate the table and then link it
> >> to itself. But how to do that?
>
> >> Thanks in advance for help!

Reply via email to