M
M
Meridian3122014-04-24 08:25:45
Ruby on Rails
Meridian312, 2014-04-24 08:25:45

How to organize a tree model that is part of another model?

class User < ActiveRecord::Base
  has_and_belongs_to :folders
end

# ...

# migration
class UsersFolders < ActiveRecord::Migration
  def change
    create_table :folders_users, id: false do |t|
      t.belongs_to :user
      t.belongs_to :folder
    end
  end
end

# ...

class Folder < ActiveRecord::Base
  has_ancestry 
  has_and_belongs_to: users
end

The main problem is that root can refer to users, but its children are nil for users.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Markov, 2014-05-03
@manameiz

The question is not entirely clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question