>> I was thinking about doing
>> budget_list=
>>db().select(db.budgets.id,db.budgets.name,db.budgets.type.name,db.budgets.m
>>onthly_amount,orderby=db.budgets.view_order).as_list()
Do you want to do this because you are getting the budget type id in
your returned rows?
Try this:
db.budgets.type.requires=IS_IN_DB(
db,
'budget_types.id',
'%(name)s'
)
More info in the book here:
http://www.web2py.com/book/default/chapter/07#Validators
Look for IS_IN_DB and IS_NOT_IN_DB.
On Dec 1, 9:40 am, Manakel <[email protected]> wrote:
> Hello,
>
> I have a model with 2 tables with a "reference" relationship between
> the two.
> => the Budget has a type and the name/attributes of this type are
> defined in the budget_types table.
>
> Now in a query on the budget table i would like to retrieve the name
> of the Budget type and not the Budget Type id.
>
> My model is:
>
> db.define_table('budget_types',Field('name','string'),Field('description','
> string'),format='%
> (name)s')
> db.define_table('budgets',Field('name','string'),Field('monthly_amount','do
> uble'),Field('type',db.budget_types),Field('view_order','integer'),format=' %
> (name)s')
>
> My current query is :
>
> budget_list=
> db().select(db.budgets.id,db.budgets.name,db.budgets.type,db.budgets.monthl
> y_amount,orderby=db.budgets.view_order).as_list()
>
> I was thinking about doing
> budget_list=
> db().select(db.budgets.id,db.budgets.name,db.budgets.type.name,db.budgets.m
> onthly_amount,orderby=db.budgets.view_order).as_list()
>
> but it fails.
>
> I guess i could do this with an explicit join but i thought there was
> a "related" feature like in django ;-)