Reputation: 31
I have 2 classes called User and Gig and also a joining table Usergig.
class Usergig
include DataMapper::Resource
property :id, Serial
belongs_to :user
belongs_to :gig
end
class Gig
include DataMapper::Resource
property :id, Serial
property :gigname, String
property :gigtext, Text
has n, :usergigs
has n, :users, :through => :usergigs
end
class User
include DataMapper::Resource
property :id, Serial
property :username, String
property :realname, String
has n, :usergigs
has n, :gigs, :through => :usergigs
end
And when i try to run:
post '/gig/add' do
user = User.get(1)
gig = user.gigs.create(:gigname => params[:gig_gigname], :gigtext => params[:gig_gigtext])
end
I get the error: NoMethodError at /gig/add undefined method `include?' for nil:NilClass
I've googled for about two hours now and read the DataMapper documentation. Anyone know what i'm doing wrong?
Upvotes: 3
Views: 760
Reputation: 5743
You forgot to call DataMapper.finalize...this is what you need to call after all your models are loaded. Rails does this for you, in Sinatra you must call it manually.
Upvotes: 1
Reputation: 2265
In Usergig try the following:
belongs_to :user, :key => true
belongs_to :gig, :key => true
Upvotes: 1