On 7/23/06, Caio Chassot <[EMAIL PROTECTED]> wrote:

On 2006-07-23, at 01:01 , Daniel N wrote:
>
> If I create a new record with associated records, to me that means
> that I need a new two new class definitions and some fixtures.  Is
> this correct?

If you can work with the existing fixtures and models, better.
Otherwise create your own.

> raise ArgumentError, "The :dependent option expects either :destroy
> or : nullify."

You'll want to change this error message too.

> So then do I just write a couple of classes, matching fixtures and
> a test file for this?
>

Yep. And do post a patch, not just altered code.

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Caio,

Thanx so much for your help.  This has helped a lot.

I wrote the change and posted a patch but the mailman decided that it was too big and needed admin approval. 

I went down the road of writing new classes and fixtures, adding into the db schemas etc.  Worked a treat, all tests passed.

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

In this case if I have a var @my_class and call @my_class.destroy, during it's before_destroy:
 1. it will look at the things and see that it has :destroy_all and go ahead and destroy them.
 2. time goes on and it gets to the before_destroy for important_things and halts the destroy action because it has some imporant_things.

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.

Again, Thanx for your time on this Caio, I really appreciate it.

Cheers
Dan


_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to