You should use the hasManyToMany for n-n relationship for the Authors and Books models, (if I'm not wrong, Author has many Books and Books has many Authors)
so you models should be like this: for Authors:
public function initialize(){
$this->setSource('Authors');
$this->hasManyToMany('ID', 'Authorbook', 'AuthorID', 'BookID', 'Books', 'ID', array(
'alias' => 'books'
));
}
same for the Books model, we have to use the hasManyToMany function:
public function initialize(){
$this->setSource('Books');
$this->hasManyToMany('ID', 'Authorbook', 'BookID', 'AuthorID', 'Author', 'ID', array(
'alias' => 'authors'
));
}
the AuthorBook model relations are correct.
Now you can get the author(s) of a book with a simple call to the alias that we have defined in the relations:
$book = Books::findFirst();
$bookAuthor = $book->authors->toArray()
that's it.