I think any discussion of denormalization needs to include aggregation
as well, since most uses will involve more than simply looking up one
value form a related model. I also think this is something definitely
to include in core. In my experience at least, denormalization occurs
a lot and leaves a lot of room for mistakes, so it's something a
framework should handle if possible.

Ideally I'd like to see either a calculation field that can take
aggregation expressions and options about how to store and
synchronize.

I imaging something like this syntax:

class Order(models.Model):
    # updates the order total if the line items change
    subtotal = models.CalculationField(Sum('items.cost'), store=True, sync=True)

    # doesn't update the order's customer name if the customer's name changes
    customer = models.ForeignKey(Customer)
    customer_name = models.CalculationField(F('customer.name'),
store=True, sync=False)

    # don't store a rarely used value. calculate on select
    weight = CalculationField(Sum('items.weight'), store=False)


This approach would require some changes to the ORM and aggregation,
but it'd be worth it since it'd make denormalization easy, flexible
and less error-prone. Fields would need to be able to contribute more
to queries and table creation, and we'd some simple need type
inference for expressions/aggregation. If calculation support is added
to all fields, or calculations have to have a declared type, then type
inference wouldn't be necessary, but type inference for aggregation
isn't hard.

-Justin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to