ClosureTree/closure_tree

STI and children.create

leonelgalan opened this issue · 2 comments

When calling create on the children's type is not passed to the newly created child.

Piggybacking on the example provided

class Tag < ActiveRecord::Base
  acts_as_tree
end
class WhenTag < Tag ; end
class WhereTag < Tag ; end
class WhatTag < Tag ; end
now = WhenTag.create name: 'Now'
now.children
=> []
right_now = now.children.create name: 'Right now'
right_now.type
=> nil

I was expecting the type to be kept. I don't know if I'm asking too much from closure_tree and this is just not supposed to be kept. Meanwhile I'll set it up manually or create the child using WhenTag.create and assign it to its parent later.

This is a known issue with Rails, I'm afraid, and it doesn't seem to be a priority to address it. Ths patch languished for a while and wasn't merged.

Rather than using the children.create, try children << or add_child. I'll add a comment to the README.

Here's example code:

95a6bb2

I also just updated the README. Thanks!