class Post has n, comments property :comments_count, Integer end class Comment belongs_to :post after :save do post.comments_count +=1 post.save end end
#ignore the other attributes So when I do something like post.comments.create() I expect the INSERT and UPDATE statements to be in the same transaction. Instead I see this: INSERT into comments BEGIN UPDATE posts COMMIT I believe that ActiveRecord would wrap all the callback in the same transaction. So in order to guarantee transaction I have to rewrite it to this. class Post has n, comments property :comments_count, Integer def add_comments comments_count += 1 comments.new(...) save end end class Comment belongs_to :post end then call post.add_comment(...) Thanks for reading. -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.