# Strange Datamapper behavior

**URL:** <https://www.ruby-forum.com/t/strange-datamapper-behavior/168706>\
**Category:** Ruby\
**Created:** [May 24, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/strange-datamapper-behavior/168706 "2009-05-24T19:11:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@rwz](https://www.ruby-forum.com/u/rwz)\
**Post date:** [May 24, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/strange-datamapper-behavior/168706/1 "2009-05-24T19:11:10Z")

</div>

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.

`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 :posted\_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 :post  
end

class Categorization  
include DataMapper::Resource

# property :id, Serial

# property :created\_at, DateTime

belongs\_to :category  
belongs\_to :post  
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, :posts, :through =\> :categorizations, :mutable =\> true  
end

DataMapper.auto\_migrate!

Then i try to do things with this models somehow:  
`
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
`

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?
