Tuesday, 13 August 2013

Better Error for DataMapper

Better Error for DataMapper

I have a database.rb source that contains:
module Record
include DataMapper::Resource
property :id, Serial
property :created_at, DateTime
property :modified_at, DateTime
property :deleted_at, DateTime
end
class Group
include DataMapper::Resource
include Record
property :name, String
property :note, Text
has n, :user
end
class User
include DataMapper::Resource
include Record
property :email, String
property :note, Text
property :created_at, DateTime
has n, :user_auth
belongs_to :group
end
class UserAuth
include DataMapper::Resource
include Record
property :authid, String
property :remote_addr, String
property :http_x_forwarded_for, String
property :user_agent, String
belongs_to :user
end
class Location
include DataMapper::Resource
include Record
property :name, String, unique_index: true
has n, :location
belongs_to :location
has n, :device
end
class Device
include DataMapper::Resource
include Record
property :name, String
property :long, Float
property :lat, Float
property :location, String
belongs_to :location
end
class LogRecord
include DataMapper::Resource
include Record
property :submitted_at, DateTime
property :sequence, Integer
property :level, Float
property :log_type, Integer
belongs_to :device
end
when i try to finalize it, an error shows:
WARNING: Nokogiri was built against LibXML version 2.8.0, but has
dynamically loaded 2.9.1
dm-core-1.2.1/lib/dm-core/model.rb:865:in `assert_valid_key': Group must
have a key to be valid (DataMapper::IncompleteModelError)
from dm-core-1.2.1/lib/dm-core/model.rb:141:in `finalize'
from dm-core-1.2.1/lib/dm-core.rb:281:in `block in finalize'
from dm-core-1.2.1/lib/dm-core/support/descendant_set.rb:64:in `block
in each'
from dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `block in
each'
from dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `block in
each'
from dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
from dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
from dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `each'
from dm-core-1.2.1/lib/dm-core/support/descendant_set.rb:63:in `each'
from dm-core-1.2.1/lib/dm-core.rb:281:in `finalize'
from database.rb:73:in `<main>' # DataMapper.finalize method call
the question would be, how to know which part of class declaration that
causes the error?
is it caused by module Record that i use to define common property
(instead of write it on each class)?

No comments:

Post a Comment