>
> db.define_table('Continent', Field('Name', 'string'))

db.define_table('Country', Field('Name', 'string'), Field('Continent', 
> db.Continent))
> db.define_table('City', Field('Name', 'string'), Field('Country', db.
> Country))
>
> Using an ORM, you could do something like:
> >>> Country(Name='France').City.list
> [<City Name:Paris>, <City Name:Nice>]
>
> 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>]
>

Actually, you can do this with the DAL:
>>> db.Country(name='France').City.select()

Almost identical to your ORM code (not that I think it needs to be similar 
looking code to be useful).

>>> 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').City.list
> [<City Name:Paris>, <City Name:Nice>]
>

In the DAL, you can do (I think I got this right):

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

Of course, you don't get the "is" equivalencies, but your example doesn't 
actually require that.

Anthony

-- 

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