On Jan 26, 4:47 pm, "Victor 'Zverok' Shepelev" <[email protected]>
wrote:
> I respect your sarcasm. But I still considering reasonable behavior like:
>
> Course.filter(...some filter...).delete(:cascade => true)
>
> which reads Course associated Section, and its associated Topic and so on,
> and deletes all associtated. I'm working on plugin with this behavior
> current night :)

Joseph Love did a good job of explaining how to do cascading deletes.
They are best handled at the database level if possible, and via a
before_destroy hook if not.

The above syntax may work for your application, and might work for a
plugin, but it would never be part of Sequel itself.  For one, it's
not possible to determine which models you should cascade to (and all
one_to_many associations would be a bad default, IMO).  If you really
want the functionality, you may want to make the API more like eager
loading:

  Course.filter(...some filter...).delete(:cascade=>{:sections=>
{:topics=>:questions}})

Personally, I think that if you don't want to use the database to do
this, you should do:

  Course.filter(...some filter...).destroy

It will call the before_destroy hook on each model returned, and you
can do something like the following to do what you want:

  Course.before_destroy{|c| c.sections_dataset.destroy}
  Section.before_destroy{|s| s.topics_dataset.destroy}
  Topic.before_destroy{|t| t.questions_dataset.destroy}

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

Reply via email to