On Sunday, March 1, 2015 at 5:55:02 AM UTC+10:30, Jeremy Evans wrote:
>
> You have a double entry accounting system where you allow modifications to 
> transactions?  In any serious accounting system, transactions are 
> immutable. Auditors would definitely frown on any accounting system that 
> allowed you to modify committed transactions.  You don't modify existing 
> transactions, you add new transactions.
>

I was using double-entry accounting as the canonical example of this kind 
of constraint, but I take your point.
 

> Implementation of this would probably not be too difficult via a database 
> extension.  Overriding Database#commit_transaction, executing the 
> before_commit if the database doesn't support savepoints or the 
> savepoint_level is 1, then calling super should probably do it.  You may 
> want to give that a shot.
>

Ok thanks, I will look at implementing a database extension.

An alternative approach is just to add a method that checks that the 
> transaction is balanced:
>

>   def DB.balanced_transaction(trans)
>     transaction do
>       yield
>       raise Sequel::ValidationFailed unless 
> trans.entries_dataset.sum(:amount) == 0
>     end
>   end
>

How might I ensure that all critical changes to a transaction or its 
entries (e.g. add, delete entry or change entry amount) go through this 
mechanism?
 

> Another possible use case for a 'before_commit' hook might be to 
>> automatically save any unsaved objects when exiting a transaction block, to 
>> avoid the need to explicitly call 'save'. I'm not sure yet whether this is 
>> a good idea but having a 'before_commit' hook would make it easy to 
>> experiment with.
>>
>
> I don't think you could do this without an identity map, that every new 
> model object registers with, which is not how Sequel::Model currently 
> works, or how I want it to work.
>

What I was thinking is that any change to a model object's attributes or 
associations would create a 'before_commit' hook that calls 
'self.save_changes'. I'll try and see how easy this is to get working.

Thanks,
Tim

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to