Forcing table name in row object?

95 views
Skip to first unread message

Marin

unread,
Aug 8, 2011, 6:23:57 PM8/8/11
to web2py-users
Hi,

If query has table JOINs, fields are accessed with:
row.tablename.fieldname.
Without JOIN, it is row.fieldname.
This is described here: http://web2py.com/book/default/chapter/06#Inner-Joins

I need it join-independent.
With or without join: row.tablename.fieldname (yes, even if SELECT has
only one table).

Is there a way to do it?

I was thinking about putting "self.tablename = self" somewhere inside
Row object creation, but i don't want to mess with core web2py
modules :-)

pbreit

unread,
Aug 8, 2011, 6:33:08 PM8/8/11
to web...@googlegroups.com
I run into that problem a lot as well and haven't figured out the best way to handle it.

Is it possible to do something like this?

    for item, auth_user in rows.item, rows.auth_user:
        ...

Marin Pranjic

unread,
Aug 9, 2011, 2:06:00 PM8/9/11
to web...@googlegroups.com
No, but it would not help me.

I want to implement "dynamic queries", actually support adding some
WHERE and SELECT parts in query (extending original queries).
And iteration through Rows object should work without knowing did
query had JOINs or not.
Problem is when original query does not have JOIN, and I extend them
with something which adds join.
Here syntax changes from row.fieldname to row.tablename.fieldname and
my view raises an exception.

Massimo Di Pierro

unread,
Aug 9, 2011, 2:18:42 PM8/9/11
to web2py-users
Now I understand:

rows = db(...).select(...)
rows.compact = False

and now you always have the rows[i].table.field syntax. no more
rows[i].field shortcuts.

Massimo

Marin Pranjic

unread,
Aug 9, 2011, 3:30:41 PM8/9/11
to web...@googlegroups.com

Thanks

Marin

On 9 Aug 2011 20:18, "Massimo Di Pierro" <massimo....@gmail.com> wrote:

Now I understand:

rows = db(...).select(...)
rows.compact = False

and now you always have the rows[i].table.field syntax. no more
rows[i].field shortcuts.

Massimo



On Aug 9, 1:06 pm, Marin Pranjic <marin.pran...@gmail.com> wrote:
> No, but it would not help me.

...

> On Tue, Aug 9, 2011 at 12:33 AM, pbreit <pbreitenb...@gmail.com> wrote:

> > I run into that proble...

Bruno Rocha

unread,
Aug 9, 2011, 5:39:42 PM8/9/11
to web...@googlegroups.com
rows = db(...).select(...)
rows.compact = False

and now you always have the rows[i].table.field syntax. no more
rows[i].field shortcuts.

Thank you Massimo, this will save some 'ifs' that i've made in my plugins. 
Reply all
Reply to author
Forward
0 new messages