Forum: Ruby on Rails awesome_nested_set is too paranoid for me :(

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pietro (Guest)
on 2009-05-22 20:42
(Received via mailing list)
So awesome_nested_set protects its parent_id attribute and even
redefines the parent_id= method. This is causing me difficulty.

My models have a uniqueness constraint on :name that is scoped by
parent_id. So I could create records with attrs

{ :name => foo, :parent_id => nil }, and
{ :name=> foo, :parent_id => 1 }

and they would be valid because they have different parents.

But, as best I can figure, to construct these with a_n_s I am supposed
to create 2 records with

{ :name => foo }

and then hit one with move_to_root and the other with
move_node_to_child(1). But I cant do that because creating 2 records
with the same name and parent_id defaulting to nil fails validation.

I think I need to specify the parent at creation time. Is there any
way I can get a_n_s to allow this??

This topic is locked and can not be replied to.