Posts Tagged ‘CastleProject

02
Nov
07

AR & Many-Many

Just a quick braindump, for setting up a many-many relation with Castle ActiveRecord.

The general setup is just like on the documentation. However to be able to store a connection in the assoc. table, AR will need mutual assginments like:


mypost.Categories.Add(cat) ;
cat.Posts.Add(mypost);
...and save all...

However, this can be neatly done, when you set one side to be the passive one , by indicating Inverse=true like in the example AND, set Cascade = ManyRelationCascadeEnum.All in the active side. This way all you need to do is:


mypost.Categories.Add(cat);

assuming the mypost belongs to the active side.