You need to create the join records after saving the initial post, so
it's an ideal case for using the afterCreate() callback. I'd do
somethinng like this, although others may have better solutions:
****************
Say your form post looks like this:
params.post.id = 1
params.post.title = 'foo'
params.post.categories = '1,2,3,4
In your model, you set up the following:
<cfcomponent>
<cffunction name="init">
<cfset hasMany(name="post-category-links",shortcut="categories")>
<cfset afterSave(method="assignCategories")>
</cffunction>
<cffunction name="assignCategories">
<cfset var categoryId = 0>
<cfloop list="#this.categories#' index="categoryId">
<cfset model("post-category-links").create
(postId=
this.id,categoryId=categoryId)>
</cfloop>
</cfloop>
<cfcomponent>
Finally in your controller all you need to do is save the post with...
<cfset model('post').create(
params.post)>
You'll need to add validation and methods to remove unused categories
depending on how you manage it, but this should get you started. The
key is to keep everything in the model.