Can somebody give me what could be the structure and content of
locations table, if that is to be defined as acts_as_tree?
Your help is appreciated and thanks in advance.
class Location < ActiveRecord::Base
acts_as_tree :order => “location_name”
end
all you need is a
“parent_id” column in the table/model. dat’s it. you’ll gain the
following methods:
location.ancestors # all parents of object
location.root # returns the first first parent in the leaf
location.self_and_siblings # the same generation of objects
location.siblings # same generation, excluding the location object
location.parent # the direct parent of the location object
location.children # the direct children of the location object or an
empty array if no children exist
Can somebody give me what could be the structure and content of
locations table, if that is to be defined as acts_as_tree?
(( missed the question; the table should be ))
table locations
id int auto_increment not null
parent_id int not null
location_name text_or_whatever not null
primary key(id) …
(you could also index the parent_id column for added performace sql
wise)
Can somebody give me what could be the structure and content of
locations table, if that is to be defined as acts_as_tree?
(( missed the question; the table should be ))
table locations
id int auto_increment not null
parent_id int not null
location_name text_or_whatever not null
primary key(id) …
(you could also index the parent_id column for added performace sql
wise)
that should suffice
enjoy
Shai…let me try with your input! I am a “newbie” in ROR
Thanks
Venu
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.