On Tue, Nov 4, 2008 at 9:08 AM, Ian Bambury <[EMAIL PROTECTED]> wrote:
> Let's say I am converting an existing SQL-type app
> There are tables for
> Customer
> Order
> OrderLine
> Product
> and I need to extract all order lines for a customer for a particular
> product
> Acme Ltd - Order 123 - Quantity 24 - Desciption: Can Of Beer
> Acme Ltd - Order 132 - Quantity 12 - Desciption: Can Of Beer
> Acme Ltd - Order 155 - Quantity 48 - Desciption: Can Of Beer
>
> All this information is in different tables. You say to keep all the data
> duplicated in one place, which is OK, but what if Can Of Beer was a typo and
> needs to be changed to Can Of Lager?
A handy rule of thumb that I use is to duplicate the data that you
want to search or filter on. In this example, you don't need that, so
you can model it in the datastore in much the same way as you did in
an SQL-backed application.
In particular, your OrderLine model might look like this:
class OrderLine(db.Model):
customer = db.ReferenceProperty(Customer)
order = db.ReferenceProperty(Order)
product = db.ReferenceProperty(Product)
quantity = db.IntegerProperty()
Then you'd fetch all your lines like this:
lines = OrderLine.all().filter('customer =',
currentCustomer).filter('product =', theProduct)
Dave.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---