Forum: Ruby on Rails acts_as_tree circular reference

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cac068c9c92719a59db960b2fa51719c?d=identicon&s=25 Iphan Iphan (iphan)
on 2006-03-08 14:21
my application is using acts_as_tree to create a directed graph.

Everyone would work fine, except that nothing prevents the user to
create a circular reference:

>> item.parent=child
>> item.save
=> true
>> child.parent=item
>> child.save
=> true

I checked in the database, and there it is: an item that has as parent
its own child!

item.parent_id = child_id


I know I could add code to prevent this from happening, but shouldn't
that be the job of acts_as_tree ?
This topic is locked and can not be replied to.