Doug,

Here's what I do in essentially the exact same scenario, though it's User >
Permission instead of User > Preference.  This is from the User object.

<cffunction name="setPermissionsById" hint="I set my permissions based upon
the supplied ID list" returntype="void" output="no" access="public">
    <cfargument name="IDlist" hint="A comma-delimited list of permission IDs
to set" required="yes" type="string" />

    <cfscript>
        var perm = "";
        var p = 0;

        IDlist = listToArray(IDlist);

        clearPermission();

        for ( p=1; p LTE arrayLen(IDlist); p=p+1 ) {
            perm = getPermissionService().getPermission(id: IDlist[p]);
            if ( perm.getIsPersisted() ) {
                addPermission(perm);
            }
        }
    </cfscript>
</cffunction>

To break it down a bit, I simply:

a) Pass in a comma-delimited list of PermissionIDs that I'm wanting to set
on the User
b) I ditch all of the existing permissions (clearPermission())
c) loop over the list (changed to an array) of IDs
d) if the ID is persisted, add it

Then save the object.  Done.

HTH


On Thu, Jan 8, 2009 at 2:13 AM, Doug Boude wrote:

> Hi all. Probably old hat to some of you (actually I'm hoping that it is),
> but I'm needing a solid little snippet illustrating/representing a blurb I
> found in a Transfer group post from back in July. The scenario is that I
> have two tables who have a many to many relationship... users to
> preferences. I edit the preferences for a given user and want to update the
> junction table's records (remove the ones that are now irrelevant, leave the
> good ones alone, add ones not currently in existence). I understand that
> Transfer can automagically do such things for me, but I can't seem to find
> the right button to push. Anywho, here's the blurb I'm referring to:
>
> "If you have the collection from one object -> another
>
> Why not just loop around your collection of objects, and then do a
> check - if it's meant to be there, keep it, if it's not,delete it,and
> if it's not there, add it.
>
> Doesn't seem like that big an issue.
>
> If you are using m2m, then it manages this for you. "
>
> If my hungry little eyes could see just one simple example of this "not so
> big issue" in action, I would be MOST greatful! :) Hypotheticals and
> non-tested snippets welcome.
>
>
>
> Doug  :0)
>

--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to