On Saturday, November 1, 2014 8:26:44 AM UTC-4, Leonel Câmara wrote:
>
> Then how in web2py would you best represent the following?
>> SELECT name FROM person
>
>
> db(db.person).select(db.person.name) 
>
> Seems reasonable to me.
>

It's not entirely unreasonable, but neither is it the most straightforward 
way to represent the logic of the request (i.e., give me all the records 
with no filtering) nor to parallel the SQL statement in question. 
db(db.person) is short for db(db.person.id != None), which is an odd api 
requirement, given that we are not interested in doing any filtering in 
this case (we are forced to construct a useless filter that doesn't 
actually filter anything). In the current api, db() represents the case 
where we don't need any filtering (WHERE clause), which is a common and 
valid use case.
 

> It just seems weird to me to infer the tables from the fields as I see 
> picking the table as a query on the database for a table with a given name.
>

We can infer "FROM person" based on "WHERE (person.id IS NOT NULL)" or 
based on "SELECT person.name". I don't see how the former is any more 
natural or intuitive than the latter. From a logical perspective, they are 
both equally valid bases of inference. From an intuitive perspective, one 
might argue that the latter actually makes more sense, as the WHERE clause 
is optional and therefore should not be required solely for the purpose of 
inferring the FROM clause.

Anyway, I suppose the discussion is moot, as changing this would break 
backward compatibility.

Anthony

-- 
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