[eluser]WanWizard[/eluser]
First of all, I'm suprised you get this far.
Relation names are case sensitive, to be able to find the mapping between the two models the case should be the same.
The same is true for the mapping between the relation names and the foreign keys. If you use 'News' as relation name, Datamapper expects a foreign key called 'News_id', and not 'news_id'.
Because Datamapper can't find the foreign key, it starts looking for a relationship table. And gives you this error because it doesn't exist too.
Code:
class NewsModel extends DataMapper {
var $table = "news";
var $has_many = array(
'comment' => array(
'class' => 'CommentModel',
'other_field' => 'news'
)
);
}
class CommentModel extends DataMapper {
var $table = "comment";
var $has_one = array(
'news' => array(
'class' => 'NewsModel',
'other_field' => 'comment'
)
);
}
Now this works fine.
Code:
$news = new NewsModel();
$news->get_by_id(1);
$news->comment->get();
Note that you have an error in your comment table definition too. There is no column called 'comment_id', so the create fails on the primary key.