Sinatra中的DataMapper错误 - NameError:找不到child_model

时间:2012-12-29 23:28:28

标签: ruby sinatra datamapper ruby-datamapper

使用Sinatra和DataMapper。这是我第一次尝试使用两个以上的模型类。不确定导致错误的原因。感谢。

错误:

NameError: Cannot find the child_model ContactNote for Contact in contact_notes

模特:

class Contact
    include DataMapper::Resource
    property :id, Serial
    property :fullname, Text, :required => true
    property :email, Text
    property :phone, Text
    has n, :contact_notes
    has n, :projects
end

class Contact_Note
    include DataMapper::Resource
    property :id, Serial
    property :contact_content, Text, :required => true
    property :created_at, DateTime
    property :updated_at, DateTime
    belongs_to :contact
end

class Project
    include DataMapper::Resource
    property :id, Serial
    property :project_name, Text, :required => true
    property :created_at, DateTime
    property :updated_at, DateTime
    belongs_to :contact
    has n, :project_notes
end


class Project_Note
    include DataMapper::Resource
    property :id, Serial
    property :project_content, Text, :required => true
    property :created_at, DateTime
    property :updated_at, DateTime
    belongs_to :project
end

1 个答案:

答案 0 :(得分:3)

Datamapper根据ruby约定对类名进行预期。它希望您的联系人备注在ContactNote课程中,而您已将其命名为Contact_Note,因此错误无法找到ContactNote。