[eluser]WanWizard[/eluser]
According to your database design, you have a many-to-many relationship to the Movie model, not a one-to many. So you have to define it as such.
Which will create the problem that your using the 'season' relation for two different tables, which is not going to work as you can define it only once.
I personally would implement this as a tree, since an episode can only belong to one season which only belongs to one serie. You can store a tree in a single table, and be more flexible. Have a look at the nested sets extension to deal with tree structures.
If you prefer join tables, I would implement this generic as well, and define a 'contains' and 'belongs_to' relation. And use a join field to define the type of relation if that is needed. In this case the definition would be
Code:
class Movie extends DataMapper {
$has_many = array(
'contains' => array(
'class' => 'movie',
'other_field' => 'belongs_to',
'join_table' => 'movie_relations',
'reciprocal' => TRUE
),
'belongs_to' => array(
'other_field' => 'contains',
'join_table' => 'movie_relations',
'reciprocal' => TRUE
)
);
}
Which needs a join table called 'movie_relations', containing the fields 'id', 'belongs_to_id' and 'contains_id'. You could add a join field called type.
So assuming that series have a type value of 'TVSERIE', you can get all series using
Code:
// get all TV series
$movie = new Movie();
$movie->contains->where_join_field('type', 'TVSERIE')->get();
disclaimer: I don't have access to a system to test this, I'm typing this from memory...