SQLFORM and specific relation

23 views
Skip to first unread message

pigmej

unread,
Nov 15, 2008, 11:07:51 AM11/15/08
to web2py Web Framework
Hi,

I have One to Many ( tableA 2 tableB ) relation in tables. I need to
be able choose ( in dropdown menu ) only these records from tableB
with are related to single record from tableA

In tableB I have information about related record in tableA, and in
tableA I have one related record from tableB ( I need this relations )

I tried like:
db.tableA.current.requires=IS_NULL_OR(IS_IN_DB(db
(db.tableB.parrent==db.tableA.id),'tableB.id','tableB.id',error_message="..."))

I have no idea what should I have in db.tableB.parrent==db.tableA.id.
With or without that is the same result ( work's fine but doesn't
filter my results )

mdipierro

unread,
Nov 15, 2008, 12:17:42 PM11/15/08
to web2py Web Framework

It is a logical issue:

db.tableA.current.requires=IS_NULL_OR(IS_IN_DB(db
(db.tableB.parrent==db.tableA.id),'tableB.id','tableB.id',error_message="..."))

does not work because when you set the validator there is no current
record (db.tableA.id). Imagine a create form. The db.tableA.id exist
only after the record is created, not when the form is displayed.

you need to set the validator in an update form:

def update():
id=request.args[0]
record=db(db.tableA.id==id).select()[0]
db.tableA.current.requires=IS_NULL_OR(IS_IN_DB(db
(db.tableB.parrent==id),'tableB.id','tableB.id',error_message="..."))
form=SQLFORM(db.tableA,record)

Massimo

pigmej

unread,
Nov 15, 2008, 12:27:30 PM11/15/08
to web2py Web Framework
Thanks I didn't know that I can specify requires not in model ;)

I known that it should be made in that way, but I cannot realize it;)

Thanks again ;)
Reply all
Reply to author
Forward
0 new messages