Hi everyone.

I have db = DAL("sqlite://blog.db") in my db.py. I can define my
tables in my models with having that statement in the model however I
cannot create relationships.

For example, this is post.py:
db = DAL("sqlite://blog.db")
db.define_table('post',
    Field('title', 'string'),
    Field('body', 'text')
)

and this is comment.py:
db = DAL("sqlite://blog.db")
db.define_table("comment",
    Field('post_id', db.post),
    Field('author', 'string'),
    Field('comment', 'text')
)

I get the following error:

Traceback (most recent call last):
  File "/home/mengu/projects/web2py/gluon/restricted.py", line 184, in
restricted
    exec ccode in environment
  File "/home/mengu/projects/web2py/applications/blog/models/
comment.py", line 5, in <module>
    Field('post_id', db.post),
  File "/home/mengu/projects/web2py/gluon/sql.py", line 1148, in
__getattr__
    return dict.__getitem__(self,key)
KeyError: 'post'

I also should note that this works fine if post_id is not db.post but
an integer or another field.

So my questions are:

1) Should I import db.post for this to work and how?

2) Must table definitions always be made on the db.py file?

Thanks.

Mengu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to