Ok. So now I can add and edit without error or duplicates. Solution was... If it breaks something else i'll post it but so far this worked for me. Please not that I am saving the product with transfer and the call the function below, passing through the saved transfer object as object and form has a hidden field in it which contains the id of the productcategory, or shelf as i call it.
<cffunction name="setRelationships" access="public" returntype="Struct"> <cfargument name="object" type="Struct" required="true"> <cfargument name="form" type="Struct" required="true"> <cfset shelf = transfer.get("basic.Shelf",ARGUMENTS.form.shelfidfk)> <cfif NOT shelf.containsProduct(ARGUMENTS.object)> <cfset shelf.addProduct(ARGUMENTS.object)> <cfset transfer.save(shelf)> </cfif> <cfreturn ARGUMENTS.object> </cffunction> On May 27, 10:46 am, Devon Burriss <de...@nervstudios.co.za> wrote: > Not sure I understand the question correctly. > I am only adding 1 at a time if that is the question. This problem is > occurring when I edit an existing Product. > I came up with a solution but the side effect (I think but have not > tested) will be that I cannot edit the Product so it is in another > category using this function. Although I'm not I could do that > anyway :) > I solved the problem as such: > > <cfif IsInstanceOf(this,"components.IMultiRelational") AND NOT > instance.object.getIsPersisted() AND NOT instance.object.getIsDirty()> > <cfset instance.object = setRelationships > (instance.object,arguments.form)> > </cfif> > ============= > <cffunction name="setRelationships" access="public" > returntype="Struct"> > <cfargument name="object" type="Struct" required="true"> > <cfargument name="form" type="Struct" required="true"> > > <cfset shelf = > transfer.get("basic.Shelf",arguments.form.shelfidfk)> > <cfset shelf.addProduct(object)> > <cfset transfer.save(shelf)> > > <cfreturn ARGUMENTS.object> > </cffunction> > > On May 27, 10:12 am, Mark Mandel <mark.man...@gmail.com> wrote: > > > > > Are you adding more than one? > > > Mark > > > On Wed, May 27, 2009 at 6:05 PM, Devon Burriss > > <de...@nervstudios.co.za>wrote: > > > > As an example I have a many to many relationship between Product and > > > ProductCategory. > > > When I edit a product, it updates the DB but I have a duplicate in my > > > Product array. This duplicate is not in the DB, just the array. > > > > Any ideas why this would happen? > > > > Thanks > > > Devon > > > -- > > E: mark.man...@gmail.com > > W:www.compoundtheory.com --~--~---------~--~----~------------~-------~--~----~ 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 transfer-dev@googlegroups.com To unsubscribe from this group, send email to transfer-dev-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/transfer-dev?hl=en -~----------~----~----~----~------~----~------~--~---