Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Strange Datamapper behavior

Reply
Thread Tools

Strange Datamapper behavior

 
 
rwz
Guest
Posts: n/a
 
      05-24-2009
I've been trying to make a simple many-to-many associations.

To get along with datamapper i copied the example from dm's homepage.
Here we have few simple models for a blog.

<code>require 'rubygems'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'

DataMapper::Logger.new(STDERR, :debug)
DataMapper.setup(:default, 'mysql://root@localhost/somedatabase')

class Post
include DataMapper::Resource

# ...or the Serial custom-type which is functionally identical to
the above:
property :id, Serial, :key => true
# ...or pass a :key option for a user-set key like the name of a
user:
property :name, String

property :title, String
property :body, Text
property :created_at, DateTime
end

class Comment
include DataMapper::Resource
property :id, Serial

property osted_by, String
property :email, String
property :url, String
property :body, Text
end

class Category
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String
end


class Post
has n, :comments
end

class Comment
belongs_to ost
end


class Categorization
include DataMapper::Resource
# property :id, Serial

# property :created_at, DateTime

belongs_to :category
belongs_to ost
end

# Now we re-open our Post and Categories classes to define
associations
class Post
has n, :categorizations
has n, :categories, :through => :categorizations, :mutable => true
end

class Category
has n, :categorizations
has n, osts, :through => :categorizations, :mutable => true
end

DataMapper.auto_migrate!
</code>

Then i try to do things with this models somehow:
<code>
post = Post.create(:title => 'first post', :body => 'first post body')
post.save
post.comments.build(:body => 'comment')
post.save
post.categories.build(:name => 'tag')
post.save
</code>

and get ArgumentError exception: The property 'post_id' is not a
public property.

Exception goes from the line containing "post.categories.build(:name
=> 'tag')".

I tried to dig in the code of datamapper to solve this, but it looks
too complicated for me.

Did anyone had this problem?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use transactions in DataMapper? Bjoern Ruby 0 10-04-2009 09:38 PM
Rubygems - 404 Error for gems.datamapper.org/yaml Old Echo Ruby 1 07-18-2008 04:54 PM
Comparing Active Record VS Datamapper...? Softmind Technology Ruby 11 02-20-2008 01:53 AM
DataMapper 0.2.5 Release Sam Smoot Ruby 0 12-20-2007 12:43 AM
ANN: DataMapper 0.2.3 Released Sam Smoot Ruby 1 11-14-2007 06:36 PM



Advertisments