Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STI and children.create #43

Closed
leonelgalan opened this issue Mar 5, 2013 · 2 comments
Closed

STI and children.create #43

leonelgalan opened this issue Mar 5, 2013 · 2 comments
Assignees

Comments

@leonelgalan
Copy link

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.

@ghost ghost assigned mceachen Mar 6, 2013
@mceachen
Copy link
Collaborator

mceachen commented Mar 6, 2013

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

@mceachen mceachen closed this as completed Mar 6, 2013
@mceachen
Copy link
Collaborator

mceachen commented Mar 6, 2013

I also just updated the README. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants