PlantCollections can contain many plants and plants can be in many collections. A many-to-many relationship with join table 'plantcollections_plants'.
Oddity: Rather than plantcollection_id in the join table I used the column name collection_id. I set up the relationship like this
Code:
class PlantCollection extends DataMapper {
var $has_many = array(
'plant' => array(
'class' => 'plant',
'other_field' => 'collection'
)
);
Code:
class Plant extends DataMapper {
var $has_many = array('image','plantcollection') ;
This setup doesn't work. From the PlantCollection perspective I get no errors, but the relationship won't save using $collection->save($plant). I assumed that the problem was my definition in the PlantModel. And proving that by calling $plant->save($collection) did indeed raise an error that the column 'plantcollection_id' was non-existent.
How would I have to define this then in the Plant model, to get it to work?
For now I solved it by renaming the column in the join table which isn't a problem in this case, but I have the feeling that there would've been another way?