On Aug 3, 2007, at 10:57 AM, Paul Colomiets wrote:

>
> Michael Bayer wrote:
>>
>> Hmmm, do you mean joining relations against a subrelation that uses
>> an aggregate like MAX ?  i'd like to see what you have in mind for  
>> this.
> Well, I think I've not explained it correctly.
>
> It looks quite like you're saying, but I want that aggregations
> to be stored (cached?) in the table.
>
> Suppose you have, a table of articles and comments on them.
> I want to have article.last_comment and article.number_of_comments
> to be stored in columns and to be updated when I'm saving Comment
> object (which e.g. has a foreign key to article).
> And I really want that to be atomic updates (update set cnt=cnt+1)
> instead of updating counter on Article instance and saving it.

we've just added the atomic update thing to 0.4 (note the uppercase  
Article which produces a column expression):

article.comment_count = Article.comment_count + 1
session.flush()

i wonder though if theres some way that could get "out of sync" with  
the actual number.  you'd have to be careful to establish this  
update.  if you wanted to use a mapper extension to do it, then youd  
have to issue the UPDATE directly, the change to the "comment_count"  
attribute wont get picked up if its established within the flush itself.



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

Reply via email to