Finding results under a tree list

Hi,
I have a list of items that are ordered according to their provenance.
Origin is ordered under a tree, so that is displays that way:

USA > LA > Los A.

Right now, i have two classes and a join table items_origins.

class Origin < ActiveRecord::Base
has_and_belongs_to_many :items
acts_as_tree :order=>“name”
end

class Item < ActiveRecord::Base
has_and_belongs_to_many :origins
end

I feel like it is unneeded to have a join_table here, and has_many
origins doesn’t seem logic.

Can anyone tell me if i am doing this correctly?

if you want a tree the simplest way is to add a collum to your db table
called parent id. thus it is its own joining table.

if however you wish to have multiple parents and children then you need
a connector table and some graph theory algorithms.

I recemend data structures and algorithm analysis by Weiss

would you then recommend the use of Gratr and acts_as_dag ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs