カテゴリー : DataMapper

[DataMapper] datamapper undefined method `include?’ for nil:NilClass

Sinatra + DataMapper で DB にデータを保存するときに、下記のようなエラーが発生しました。

datamapper undefined method `include?' for nil:NilClass

書いたコードは、Model の new, create などで、元々あるはずのメソッドを使うと、定義されていないというエラーが発生していました。

原因は、モデルの宣言後にファイナライズ処理をしていなかったせいだったみたいです。

調べてみると、DataMapperの公式ドキュメントにちゃんと書いてありました。

Finalize Models

After declaring all of the models, you should finalize them:

DataMapper.finalize

・引用元:DataMapper – Getting started with DataMapper はてなブックマーク - DataMapper - Getting started with DataMapper

使い始める前に、ちゃんとドキュメントに目を通しておくべきですね。。。

以上です。

【参考】

#159: undefined method `include?’ for nil:NilClass in 1.2.0 but not 1.1.0 – Issues – datamapper/dm-core – GitHub はてなブックマーク - #159: undefined method `include?' for nil:NilClass in 1.2.0 but not 1.1.0 - Issues - datamapper/dm-core - GitHub

The Future is Now: DataMapper.finalize はてなブックマーク - The Future is Now: DataMapper.finalize

[Ruby] DataMapperで利用できるデータ型

Ruby用 ORM である DataMapper で利用できるデータ型を調べたのでメモ。

DataMapperで利用できるデータ型(Available Types)

DM-Cpre は以下のプリミティブ型をサポートしています。

(DM-Core supports the following ‘primitive’ data-types.)

  • Boolean
  • String
  • Text
  • Float
  • Integer
  • Decimal
  • DateTime, Date, Time
  • Object, (marshalled)
  • Discriminator
  • Binary

・引用元:DataMapper – Properties はてなブックマーク - DataMapper - Properties