[eluser]defeed[/eluser]
Hello, I'm quite new to CI and MVC in general, so I'd be very thankful if anyone could show me how to do one thing with DataMapper. When I read the DM manual, everything seemed quite clear for me, but I kinda stuck after that when it came to many-to-many table relationships.
Basically I want to make a simple movie catalog, which lists all movies, movies by certain criteria and shows movie details.
The problem is that I use many-to-many relationship and I don't know how to output data from movie's related tables, like genres, directors and actors. To make it simple, let's just use movies and genres tables. Movie can have many genres, and genre can belong to many movies. I've setup the database, so there is 'movie' table, 'genre' table and the join table with 'id', 'genre_id' and 'movie_id' fields.
The 'movie' model looks like this:
Code:
class Movie extends DataMapper {
var $has_many = array('genre');
function __construct()
{
parent::__construct();
}
}
And this is 'genre' model:
Code:
class Genre extends DataMapper {
var $has_many = array("movie");
function __construct()
{
parent::__construct();
}
}
So, my question is how to correctly fetch movie information and all it's genres in a controller and to pass this data to a view?