> On 02/05/13 22:20, Arnon Marcus wrote: 
> > Using the DAL, the best you might get is: 
> >  >>> [city for city in db.City.Country.select() if city.Country.Name == 
> > ''France'] 
> > [<Row Name:Paris>, <Row Name:Nice>] 
> > 
>
> Anthony's suggestion: - 
>
>  >>> db.Country(name='France').City.select() 
>
>
It is a comparison between 2 options to do the same thing in web2py, not a 
comparison between a web2py way of doing it, vs. my suggested-API's way of 
doing it.
Yes, Anthony is right - there is a better-looking way of doing that 
compared to what I thought would be the best you could get from the DAL.
But it is not a testament to web2py's superioriy/equivalence to my 
suggestions (only to my poof familiarity with some web2py DAL usages), as 
there is none in that case.
If you would construct an equivalence in my suggestion in this case, it 
would look like this:
Country(name='France').City.list
vs.
db.Country(name='France').City.select() 

Now, there are syntactic as well as semantic differences here.
Syntactically is it shorted and more concise.
Semantically, it returns very different kinds of objects.
They both may represent rows in the the same table in the database, but 
they would be fundamentally diffenet in their utility - which would be a 
function of their API-context.
A sequence of ORM objects is no the same thing as a ROWS object - they 
differ less in what they contain, and more with what you can do with them.
The exact same difference goes for the second comparison:

>  >>> europe = Continent(Name='Europe') 
> >  >>> france = Country(Name='France', Continent=europe) 
> >  >>> paris = City(Name='Paris', Country=france) 
> >  >>> nice = City(Name='Nice', Country=france) 
> >  >>> 
> >  >>> europe.Country(Name='France') is france 
> > True 
> >>>> france.City(Name='Paris') is paris 
> > True 
> >  >>> europe.Country(Name='France').City.list 
> > [<City Name:Paris>, <City Name:Nice>] 
> > 
>
> Anthony's suggestion: - 
>
>  >>> europe = db.Continent.insert(Name='Europe') 
>  >>> france = db.Country.insert(Name='France', Continent=europe) 
>  >>> paris = db.City.insert(Name='Paris', Country=france) 
>  >>> nice = db.City.insert(Name='Nice', Country=france) 
>  >>> db.Country(france).City.select() 
> [<Row Name:Paris>, <Row Name:Nice>]  
>

In my suggestions, you get an ORM instance, which can do more things.
In the first example, you get a Rows object, and in the second you get an 
ID.
Granted, you could use the ID in a DAL context, in a similar way that you 
would use an ORM-class-instance within the ORM context, but there are other 
things that an ORM-object can do within an ORM context (aside from these 
examples), that an ID or a Rows object can not do in the DAL context.

-- 

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