On 7/25/06, Caio Chassot <[EMAIL PROTECTED]> wrote:
I've had a crack at this one and it is as I feared.
If I define the restrict association first, then the destroy chain is halted and all is well. But if I have an association where a :dependent => :destroy is declared before the association with :restrict then the first association is destroyed before the destroy chain is halted.
I have taken my first real plunge into the rails source and found a number of places where I thought a transaction might go to prevent this but to no avail. Actually my head is spinning a bit trying to put all the pieces of active_record together.
For this to work I think I need to put a transaction around the entire destroy chain, but I have no idea how to do this.
Any pointers anyone could give would be great.
Thanx
Dan
> Since I posted that patch tho I have been thinking. What would
> happen in this situation.
>
> class MyClass < ActiveRecord
> has_many :things, :dependent => :destroy_all
> has_many :important_things, :dependent => :restrict
> end
>
> Does this mean that things are destroyed or is the whole thing
> wrapped up in a transaction that gets rolled back if the destroy as
> a whole fails?
>
> If it partially deletes some things, then halts when it reaches an
> association with the restrict option I don't think this is robust.
The behavior is really up to you, isn't it?
I'd say write a test case for mixed dependent types, and make sure
you get the rollback you desire.
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core
I've had a crack at this one and it is as I feared.
If I define the restrict association first, then the destroy chain is halted and all is well. But if I have an association where a :dependent => :destroy is declared before the association with :restrict then the first association is destroyed before the destroy chain is halted.
I have taken my first real plunge into the rails source and found a number of places where I thought a transaction might go to prevent this but to no avail. Actually my head is spinning a bit trying to put all the pieces of active_record together.
For this to work I think I need to put a transaction around the entire destroy chain, but I have no idea how to do this.
Any pointers anyone could give would be great.
Thanx
Dan
_______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core