On Monday, July 7, 2014 4:47:34 AM UTC-7, Hiroyuki Sato wrote:
>
> Hello members.
>
> I would like to remove node 'dd' with children at once (or twice)
> operation.
>
> I wrote below code, It works.
> But I would like to use sub-query for huge nodes.
>
> It is possible to use sub-query or something for that?
>
> Like this
>
> FileTree.filter(:id => dd.all_children_data_set ).delete
> FileTree.filter(:id => dd.id).delete
>
>
> Below is my code.
>
> DataBase = Sequel.connect("sqlite://test.db")
>
> class FileTree < Sequel::Model
> plugin :rcte_tree, :single_root => true
> end
>
> DataBase.transaction do
> root = FileTree.root
> node = root.children_dataset.first(:name=>'dd')
> ids = node.descendants.map(&:id)
> ids << node.id
>
> FileTree.filter(:id => ids).delete
> end
>
This should use a subquery:
FileTree.where(:id=>FileTree.root.children_dataset.first(:name=>'dd').descendants_dataset.select(:id)).delete
Thanks,
Jeremy
--
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.