Pav*_*bin 1 ruby ruby-on-rails ruby-on-rails-4
我正在尝试设计一个与自身有关系的模型
模型:
class Department < ActiveRecord::Base
belongs_to :organization
has_many :positions
has_many :sub_departments, class: 'Department', foreign_key: 'parent_id'
end
Run Code Online (Sandbox Code Playgroud)
移民:
class CreateDepartments < ActiveRecord::Migration
def change
create_table :departments do |t|
t.string :name
t.references :parent, index: true
t.references :organization, index: true
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
当我打电话时,Department.first.sub_departments我得到一个错误:NoMethodError: undefined method 'relation_delegate_class' for "Department":String.我究竟做错了什么?
谢谢!
| 归档时间: |
|
| 查看次数: |
490 次 |
| 最近记录: |