Hi guys, 

I have a doubt here about he best way of show a *reference* value.

I'll use a simple example to illustrate, I have the following tables:


db.define_table('city',
        Field('name', type='string')
)
db.define_table('state',
        Field('name', type='string')
)
db.define_table('user',
        Field('user_name', 'string'),
        Field('user_city', 'reference city'),
        Field('user_state', 'reference state')
)


When I list the *user* table data in the view, *user_city* and *user_state* 
show their *id's*. It's OK.

So, to display the value of another field, not the Id, I usually do so:

In the controller:


list = db(db.user.id>0).select(
        db.user.ALL,
        db.state.ALL,
        db.state.ALL,
        left = [
            db.state.on(db.state.id == db.user.user_state),
            db.city.on(db.city.id == db.user.user_city)
        ]
        )
    return dict(list=list)


And in the view:


{{for data in list:}}
<tr>
    <td>{{=data.user.user_name}}</td>
    <td>{{=data.city.name}}</td>
    <td>{{=data.state.name}}</td>
</tr>
{{pass}}

And it works very well, but I discovered here that I can make it in a more 
simple way:

In controller:

list = db(db.user.id >0).select()
    return dict(list=list)

In the view:

{{for data in list:}}
<tr>
    <td>{{=data.user_name}}</td>
    <td>{{=("%(name)s" %data.user_city)}}</td>
    <td>{{=("%(name)s" %data.user_state)}}</td>
</tr>
{{pass}}

So my question is if I can use this second format, without mounting a join 
as I did in the first example. What is the best (efficient) format? and why?


Thanks to all!!
































-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to