Neither the updated version of DM nor DM itself currently support information associated with the join table, which I have to assume is what you want.
Right now, the closest you can get is to create a dedicated “relationship object”, as I think of them, that contains the two objects and the extra relationship info.
I use this to connect Contacts with other Contacts, for example (like Company/Employee):
class ContactRelationship extends DataMapper {
has_one = array(
'parent' => array(
'class' => 'contact',
'other_field' => 'related_contacts'
),
'contact'
);
// add fields, etc
}
class Contact extends DataMapper {
has_many = array(
'contactrelationship',
'related_contacts' => array(
'class' => 'contactrelationship',
'other_field' => 'parent'
)
);
// etc
}
Table:
contactrelationship
id serial PRIMARY KEY,
parent_id integer,
contact_id integer,
other_junk character varying,
etc
Usage:
$contact = new Contact();
$contact->get_by_id($id);
$contact->related_contacts->join_related('contact', array('id', 'name'))->get();
foreach($contact->related_contacts->all as $rel) {
echo $rel->contact_name . ' [' . $rel->contact_id . ']';
// change contactrelationship type
$rel->type = 'Batman';
$rel->save();
}
// If you need to edit the related contacts, try this slight hack
$rel_contacts = new Contact();
// this is the *field name* of the parent side of the relationship.
$rel_contacts->where_related('contactrelationship', 'parent_id', $contact->id);
$rel_contacts->join_related('contactrelationship', array('id', 'type'));
$rel_contacts->get();
foreach($rel_contacts->all as $rel_contact) {
echo $rel_contact->name . ' is a ' . $rel_contact->contactrelationship_type;
$rel_contact->is_happy = TRUE;
$rel_contact->save();
}
I can’t provide too much more help than that. Alternatively, you might have to rethink your design. Maybe you can use a dedicated model to keep track of more general permissions (which is how I do it). It depends on your needs.
I’ve actually been thinking about how to implement join table parameters for a while, but it always ends up making everything really complicated.