[eluser]WanWizard[/eluser]
I would say:
books -> has_many -> chapters
chapters -> has_one -> books
chapters -> has_many -> pages
pages -> has_many -> chapters
This is straitforward Datamapper, no need to create such a relationship, as there is no direct relation between books and pages. That means no complicated join tables, just use
Code:
class Book extends Datamapper {
$has_many = array('chapter');
}
class Chapter extends Datamapper {
$has_one = array('book');
$has_many = array('page');
}
class Page extends Datamapper {
$has_many = array('chapter');
}
This will require a book_id in the chapters table, and a relationship table called chapters_pages, containing chapter_id and page_id, to create the many-to-many relation between the two.
With a setup like this, your expected usage just works.