Hi everyone, I just figured out what I was doing wrong. My code was similar to Pauls option 1 however instead of calling the getter I was calling the setter.
It's all working - thanks Transfer! Cheers Matthew On Feb 20, 9:13 am, Matthew <[email protected]> wrote: > Hi everyone > > Thanks for the replies. You can probably tell that I'm new to > Transfer. Let me try and paint a picture from the UI point of view. > The customer is filling out a form field with various text fields > relating to fields in the gallery table. One of the form fields is a > drop down so they can select a product to link the gallery record to. > All I'm trying to do is save their data. Therefore I thought that to > do this I have to create a new gallery object, call all the setters > which relate to each text field and then somehow call a setter to pass > in the productId (which is a secondary key to the product table). It's > pretty simple and common UI scenerio, I'd be amazed if I had to go to > all that work of creating decorators. Another way of looking at it is > if you look at the XML below, when you are inserting a new Gallery > record how do you set a value into the ProductId field of the Gallery > table? > > <object name="Gallery"> > <id name="GalleryId" column="galleryId" type="numeric"></id> > <id name="TestField" column="TestField" type="string"></id> > <manytoone name="Product"> > <link column="ProductId" to="Product"/> > </manytoone> > </object> > > @Paul, to be honest I thought that your suggestion of creating a new > product object and passing it to a setProduct method in order to > insert the Secondary Key would make sense. I'm just amazed that I have > to do all the extra work of creating a decorator. The whole point of > Transfer is to reduce the amount of code you right. > > @Mark; don't get me wrong, I think Tranfer is great, it's probably > just me not having worked out how to do what I want to do. You are > right the setProductId doesn't make sense, I just put that in to try > and describe what I'm trying to do. I was thinking along the lines of > Paul's suggestion. > > Cheers > Matthew > > On Feb 20, 1:59 am, Paul Marcotte <[email protected]> wrote: > > > Matthew, > > > Transfer does not generate methods to create compositions based on your FK > > names. Therefore, if you wish to use that convention, you must use a > > decorator and and behaviour to your BO. You have two choices. > > > 1. > > > objGallery = transfer.getTransfer().new("Gallery"); > > objProduct = > > transfer.getTransfer().get("Product",form.Id);objGallery.setTestField("cat"); > > objGallery.setProduct(objProduct); > > transfer.getTransfer().save(objGallery); > > > 2. > > > Add a method to your Gallery Decorator > > > <cffunction name="setProductId" returntype="void" output="false" > > access="public"> > > <cfargument name="ProductId" required="yes" type="numeric" /> > > <cfset var product = > > getTransfer().get("Product",arguments.ProductId)> > > <cfset getTransferObject().setProduct(product) /> > > </cffunction> > > > If you go with option 2, I'd recommend a "get" method that returns the > > productId. > > > Why does it work this way? Tranfer ORM is an "object relational mapper", so > > one should make every effort to augment their thinking for table relations > > to object relations. It's not easy. I had a difficult time making the > > adjustment. > > > Best of luck! > > > Paul > > > On Thu, Feb 19, 2009 at 4:31 AM, John Whish > > <[email protected]>wrote: > > > > I find the getMemento method is really useful for debugging as you can see > > > what is persisted. Just do <cfdump var="#objGallery.getMemento()#" /> > > > BTW: getMemento is ONLY for debugging :) > > > -- > > Paul Marcotte > > Fancy Bread - in the heart or in the head?http://www.fancybread.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 [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 -~----------~----~----~----~------~----~------~--~---
