Cannot find child_model (NameError)

I cannot determine why a name error occurs here. I am new to DataMapper, but try to create associations. Any help is appreciated.

User:

class User
  include DataMapper::Resource

  property :id,            Serial, :key => true
  property :first_name,    String
  property :last_name,     String
  property :company,       String
  property :city,          String
  property :country,       String
  property :mobile_number, Integer
  property :email_address, String
  property :shahash,       String
  property :isRegistered,  Boolean

  belongs_to :event, :required => true
end

DataMapper.auto_upgrade!

Event:

class Event
  include DataMapper::Resource

  property :id,          Serial, :key => true
  property :name,        String
  property :occuring,    DateTime

  has n, :user
end

DataMapper.auto_upgrade!
+3
source share
2 answers

I think the problem is what you call DataMapper.auto_upgrade!after each model definition. When you name it only after defining one model, there is no child model. Instead, you should define and / or require all your models, and then do the following:

DataMapper.finalize      # set up all relationships properly
                         # and do a basic model sanity check
DataMapper.auto_upgrade! # create database table if it doesn't exist
+6
source

DataMapper.finalize(, finalize )

//init.rb

require_relative 'file_name'
require_relative 'another_model_file_name'

DataMapper.finalize

require_relative 'models/init'
0

All Articles