> User( [user_id], fname, lname, ... )
> Item( [item_id], label )
> ItemOrder( [user_id, item_id], amount )
> This shows a many-to-many relationship (ItemOrder) with an attached
> attribute (amount). Modeling this in SQLAlchemy was very easy. And
> it's a very common situation. How well web2py handles this, I cannot
> say.
db.define_table('user',SQLField('fname'),SQLField('lname))
db.define_table('item',SQLField('label'))
db.define_table('order',SQLField('user',db.user),SQLField
('item',db.item),SQLField('amount','double'))
purchases=(db.user.id==db.order.user)&(db.item.id==db.order.item)
rows=db(purchases).select(db.user.ALL,db.item.ALL,db.order.amount)
for row in rows:
print row.user.fname, row.user.lname, row.item.label,
row.order.amount
Of course we can do aggregates too
total=db.order.amount.sum()
rows=db(purchases).select(db.user.ALL,total,orderby=db.user.lname|
db.user.fname,groupby=db.user.id)
for row in rows:
print row.user.fname, row.user.lname, 'spent', row._extra
[total]
I'd argue that we do not need as much documentation for the DAL as
SQLAlchemy because it more intuitive. But this is a personal opinion.
Massimo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---