1

Using Sinatra and DataMapper. This is my first time trying to use more than two model classes. Not sure what is causing the error. Thanks.

The error:

NameError: Cannot find the child_model ContactNote for Contact in contact_notes

The models:

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
Erik D
  • 47
  • 1
  • 6

1 Answers1

3

Datamapper makes expectations on class names based on ruby conventions. It expects your contact notes to be in a ContactNote class, while you've named it Contact_Note, hence the error it can't find ContactNote.

quandrum
  • 1,608
  • 1
  • 11
  • 14
  • Thanks. This works. I noticed that even if I change the class to ContactNote I have to leave the association property as :contact_notes. If I remove the underscore there I get a similar error. Is this another datamapper convention? – Erik D Dec 30 '12 at 17:14
  • This is a ruby convention in general. – quandrum Dec 31 '12 at 01:42