Many To Many Relationships - managed from both sides?

Nov 9, 2011 at 11:51 PM

Can SLAM be configured to keep in sync a many-to-many relationship?  If so, how?  

For example, I have two lists: Users & Projects.  I want to be able to add/remove users from the Project page in SharePoint, *and* be able add/remove projects from the User page.  Would this be how we would configure it (using the same joining table):

  <DataMapping DataSchema="SLAM">
    <List Site="/IT/" Name="Projects" ActivationOrder="1" >
      <Fields>
        <Field Name="Project Name" SqlType="varchar(100)"
               SPType="Text" Required="true" />
        <Field Name="UsersOnProject" SPType="Lookup"
               AssociatedList="List" AssociationName="UsersProjects" />
      </Fields>
    </List>

    <List Site="/IT/" Name="Users" ActivationOrder="2" >
      <Fields>
        <Field Name="User Name" SqlType="varchar(255)"
               SPType="Text" Required="false" />
        <Field Name="Projects User Is On" SPType="Lookup"
               AssociatedList="List" AssociationName="UsersProjects" />
      </Fields>
    </List>
  </DataMapping>

Developer
Nov 10, 2011 at 5:52 PM

I highly recommend you not try to do this without custom code, because SharePoint will not ensure the reciprocity of relationships.  If you change projects for a User that will obviously not change the relevant project items.  Even with a many-to-many relationship it is still best to think of them as directional due to a dependence on their representation in SharePoint.  I recommend you pick one, say Users, to be the authority, then create an event receiver for Projects.  When a Project is saved then it would update the relevant Users, and of course on Update the User will be slammed.  You will need to solve the reciprocity problem in any case as SLAM would save relationships on saving an item in one list (deleting all relationships for that item then creating updated ones) without regard for the items in the other list.