cakephp/cakephp — pull request #4302 by ibejohn818 (2014-08-19 03:52:46+00:00)
Title: Add insertData option to belongsToMany association to insert additional data to joinTable

I've added an 'insertData' option to the belongsToMany relationship to insert additional data into the join table.

'insertData' => ['Column'=>'Data']

This is useful when using a single join table for belongsToMany relationships.
IE:
Tags
-ID
-TagName

Posts
-ID
Name

TaggedModels
-ID
-tag_id
-foreign_key
-model

You can set your belongsToMany relationship as:
PostsTable.php
$this->belongsToMany('Tags',[
'joinTable'=>'tagged_models'
'foreignKey'=>'foreign_key'
'conditions'=>['model'=>'Posts']
'insertData'=>['model'=>'Posts']
]);

This could also be useful for other use-cases.
It's a simple addition, however, I'm not very comfortable with the frameworks TestSuite so I could use some help there if this additional is deemed worthy to be added.