This saves our new Category and adds the Post with the primary key of 5, 6, 7 and 10 in the Databases. 5 Queries will be performed here, one for the Category-Model and four for the N:M-Table tbl_post_category.

I also made a change to CHtml so CHtml::activeCheckboxList works where receiving an array of relation objects. Just pass a parameter "attributeitem" into htmlOptions with the attribute name of the objects.

Using these 2 codes I was able to make a checkboxlist onto a many-many table without any code changes.

The fields identifying both Tables in the MANY_MANY Table doesn't necessarily need to be called like the primary key of the Tables. That's why you first have to resolve the name of the field from the relation[3] like this:

that's great Code from UX.Infogate! Looks much more tidied than my Version. If you like, i will use this as a codebase for future Versions of the AdvancedArBehavior. Maybe this whole stuff get's included in the Core ActiveRecord as soon as it gets [even more] more stable.

1. It calls the parent afterSave and beforeDelete methods, but afaik, that is not needed in a behavior.
2. This may not be an issue, but shouldn't "behavior" be uppercased in the class definition? (extends ...Behavior?)

If you like, i will use this as a codebase for future Versions of the AdvancedArbehavior

That's will be great!!!

intel352, on 08 March 2010 - 12:36 PM, said:

Couple of notes on UX.Infogate's version:

1. It calls the parent afterSave and beforeDelete methods, but afaik, that is not needed in a behavior.
2. This may not be an issue, but shouldn't "behavior" be uppercased in the class definition? (extends ...Behavior?)

1. It was done because of possible future features of ActiveRecordBehavior class.
2. It is issue of source code highlighter. If you get a look at HTML-code of this page you can find that "behavior" word displaying correctly.

a long time nothing has changed in this extension. But now i found this forum thread that could make this extension even better. I am going to implement this 'automatic database syncinc' feature mentioned there in the CAdvancedArBehavior, make it toggleable (default to off) and will release 0.3 of this Version. Hopefully i will be able to merge UX.Infogate's changes and code into this Version.

Is anyone interested to help develop this extension via svn? i ask because the 'newest' version is always available here

Being a total newbie this might be a really stupid question but I'd still like to ask it.
I've downloaded this extension, placed it in the autoimport array (in main.php), added the MANY_MANY relation to my model, plus the bahaviors() method to decorate the class with this new behavior and now... I'm stuck.

I can get my view to display the related items just fine.
Code in view:

What do I have to do to actually save the stuff chosen on my form?
Committing the form will not save the values in my MANY_MANY table. And I'm not really expecting it to work out-of-the-box but I'd like to have a pointer, what I need to use. Where in the controller do I need to add something?

I think I found a bug in thyseus's CAdvancedArBehavior. I will use model situation from extension's documentation with Categories and Post to explain problem.

Assume I have already some Categories an Posts in DB. If I fetch $singleCategory = Category::model()->find(CRITERIA) I get a Category object, where may be array of some Posts in $singleCategory->posts. Bug occurs when I clear all Posts from relation: $singleCategory->posts = array()

Expected behavior should be deletion all of Posts from Category. But this fails any no change is made. This is very strange to me, cos removing Posts from Category works fine (like this):