On Tue, Mar 3, 2009 at 8:35 PM, weheh <[email protected]> wrote:
>
> That works. But I don't understand it. Is this something that should
> be obvious from the documentation, and therefore I didn't read
> carefully enough, or do I need to look at the source to understand
> this?
Maybe being this explicit would help:
> db.py:
> db.define_table('test',SQLField('auth_user_id',db.auth_user),
> SQLField('name','string'))
you see, db is the database name (it could be any variable name);
db.auth_user is the table name - maybe it would be clearer to write the
equivalent:
SQLField('auth_user_id', 'reference auth_user'),
since you cannot have a column hold an entire table (!) - this is a foreign
key - so it is implicit that this is
a reference to a row in that table; in web2py the unique identifier of any
table row is always (by convention,
and done automatically) "id"
>
> controller.py:
> def create():
> form=FORM(...)
> if form.accepts(request.vars,session):
> id=db.test.insert
> (name=form.vars.name,auth_user=db.auth_user) ???????
...then this would be more readable as:
(name=form.vars.name,auth_user_id=db.auth_user.id)
You can see examples that use the *_id suffix convention in naming foreign
keys in much of the web2py documentation to help remind you that it's a
reference, and references are named id in the target tables.
Does this help?
Kind regards,
Yarko
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---