DataMapper Error with Models(`fetch': key not found: :precision (KeyError))

487 views Asked by At

Really new to programming and the programming community, and this is only my second project programming with ruby so excuse me if I'm missing something obvious or doing something wrong.

In this project so far, I'm trying to create a database using Datamapper. The database should include three objects: User, Category, and Class. User can have many Category, and a Category can belong to many users, which is why I linked these two objects with UserCategory to create a many-many relationship. Another association is between the Category and Class, which is that a Category object can have many classes, but a class can only belong to one Category. This is my database so far:

require "sinatra"
require "data_mapper"
if ENV['RACK_ENV'] == 'production'
  DataMapper.setup(:default, ENV['DATABASE_URL'])
else
  DataMapper.setup(:default, "sqlite:online-arena.db")
end

class User
  include DataMapper::Resource

  property :id,           Serial

  property :username,     String,
    :required => true,
    :unique   => true

  property :password,     BCryptHash, :required => true
  validates_confirmation_of :password

    attr_accessor :password_confirmation
    validates_length_of :password_confirmation, :min => 6

    def valid_password?(unhashed_password)
      self.password == unhashed_password
    end

  property :admin,       Boolean, default: false

    has n, :user_categories
    has n, :categories, through: :user_categories
end

class UserCategory
  include DataMapper::Resource

  property :id,         Serial

  belongs_to    :user
  belongs_to    :category
end

class Category
  include DataMapper::Resource

  property :id,           Serial
  property :title,         String

  has n, :class

  has n, :user_categories
  has n, :users, through: :user_categories
end


class Class
  include DataMapper::Resource

  property :id,           Serial
  property :name,         String
  property :teacher,      String
  property :spots,        Integer

  belongs_to :category
end


DataMapper.finalize
DataMapper.auto_upgrade!

These are the gems I'm using for this project:

source "https://rubygems.org"

gem "sinatra"
gem "data_mapper"
gem "bcrypt"
gem "rake"

group :development do
  gem "sqlite3"
  gem "dm-sqlite-adapter"

  gem "dotenv"
  gem "rerun"
end

group :production do
  gem "pg"
  gem "dm-postgres-adapter"
end

I'm using Cloud9 to work on this project and so far, I have "bundle install --without production", and then launched it with "ruby online-arena.rb -p $PORT -o $IP" but it's giving me this error:

/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-core-1.2.1/lib/dm-core/property/numeric.rb:19:in `fetch': key not found: :precision (KeyError)
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-core-1.2.1/lib/dm-core/property/numeric.rb:19:in `initialize'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-core-1.2.1/lib/dm-core/property/integer.rb:15:in `initialize'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-core-1.2.1/lib/dm-core/model/property.rb:55:in `new'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-core-1.2.1/lib/dm-core/model/property.rb:55:in `property'
    from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/dm-validations-1.2.0/lib/dm-validations/auto_validate.rb:11:in `property'
    from /home/ubuntu/workspace/models.rb:49:in `<class:Class>'
    from /home/ubuntu/workspace/models.rb:46:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
    from /home/ubuntu/workspace/environment.rb:5:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
    from online-arena.rb:4:in `<main>'

If there isn't enough information, here's the rest of the files on my github https://github.com/FuriousPenguins/Online-Arena


I tried using my previous project's database model that has a similar layout:

https://github.com/kichoy/lunch-reviews/blob/master/models.rb

and I was able to run the application.

0

There are 0 answers