Hello,

I was checking the SQL statements used by web2py and found that the id 
field of a table is always added to the orderby when using a grid (didn't 
test in other forms).
Even if the grid definition doesn't include a orderby argument, web2py 
always adds the ORDER BY id.

Does anyone know why?

And how to remove it?

Here is an example:

        table = db.client

        grid = SQLFORM.grid(
            table,
            csv=False, details=False,
            ondelete=on_delete,  # Grid only.
            onvalidation=on_validation,  # Form only.
            orderby=db.client.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid and view form only.
        )

This is the SQL statement that web2py uses for the grid above (see the 
addition of the client.id to the ORDER BY)

        SELECT client.id, client.code, client.name, client.canceled_on,
        client.canceled_by, client.cancel_approved_by, client.is_active,
        client.created_on, client.created_by, client.modified_on, 
client.modified_by
        FROM client WHERE (client.id IS NOT NULL) ORDER BY client.name, 
client.id;

If I remove the orderby from the grid's definition, the SQL statement that 
web2py uses still includes the ORDER BY id

        SELECT client.id, client.code, client.name, client.canceled_on,
        client.canceled_by, client.cancel_approved_by, client.is_active,
        client.created_on, client.created_by, client.modified_on, 
client.modified_by
        FROM client WHERE (client.id IS NOT NULL) ORDER BY client.id;


Thanks,

JM

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to