ClosureTree / closure_tree

Easily and efficiently make your ActiveRecord models support hierarchies
https://closuretree.github.io/closure_tree/
MIT License
1.83k stars 239 forks source link

Unknown primary key for table page_hierarchies in model PageHierarchy #294

Open mcmegavolt opened 6 years ago

mcmegavolt commented 6 years ago

I'm using rails 5.1.4 with activeadmin

When try to load pages index in ActiveAdmin got the error

Showing /home/ap/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activeadmin-1.2.0/app/views/active_admin/resource/index.html.arb where line #2 raised:

Unknown primary key for table page_hierarchies in model PageHierarchy.

def primary_key(klass)
  klass.primary_key || raise(UnknownPrimaryKey.new(klass))
end

My page model

class Page < ApplicationRecord
  ...
  has_closure_tree order: 'sort_order'
  ...
end
hirokishirai commented 6 years ago

+1

mmorast commented 6 years ago

+1

tomlockwood commented 6 years ago

+1

danthecrane commented 6 years ago

+1

aykc commented 6 years ago

Try: rails g migration AddPrimaryKeyToPageHierarchies id:primary_key rails db:migrate This helped to me

mmitchellg5 commented 2 years ago

Will this PK added cause any issues?

aykc commented 2 years ago

probably not, it's just a regular primary key field