If you set the Item value, which is the key AFTER you add it to the
collection (setParent()), it's going to add it to the struct with ''
as the key... twice, one overwriting the other.
Mark
When I dump the userProfile bean or the user memento I see the Settings
collection is an array, not a struct. Is it stored like this internally
though?
Ah I see what you mean about the setParent... So the correct way is to
create the userProfileSetting first, then set the item and value and finally
attach it to the parent?
I may have this all confused as I haven't tried a collection with a struct
yet. I wanted to have quick access to all the settings with the item as the
key.
Cheers,
James.
<!--- The presence of the value new signifies a new temperature --->
<!--- Since it's a new temperature, we create a new Temperature transfer object ... --->
<cfset session.temperatureTO = getTransfer().new("Temperature") />
<!--- ... and then we loop thru the active languages to create and set the child transfer objects in TemperatureTO
and set some values in each temperatureLanTO --->
<cfloop query="qActiveLans">
<cfset temperatureLanTO = getTransfer().new("TemperatureLan") /><!--- create a new TemperatureLan transfer object --->
<cfset temperatureLanTO.setLan(lan) /><!--- set the lan of the new TO while in the loop --->
<cfset temperatureLanTO.setParentTemperature(session.temperatureTO) /><!--- set the parent object --->
</cfloop>
<!--- Find the maximum sortOrder value and set this sortOrder value +1 --->
<cfset session.temperatureTO.setSortOrder(getAdminGateway().findNextTemperatureSortOrderValue()) />
<cfset arguments.event.setValue("temperatureTO", session.temperatureTO) />
<cfelseif arguments.event.ValueExists("id")><!--- this signifies an existing temperature being edited --->
The memento is always a array. Dump the getSettingStruct();
>
> Ah I see what you mean about the setParent... So the correct way is to
> create the userProfileSetting first, then set the item and value and finally
> attach it to the parent?
Yep, if you don't set the key first, how is it meant to know what the
key should be ;o)
>
> I may have this all confused as I haven't tried a collection with a struct
> yet. I wanted to have quick access to all the settings with the item as the
> key.
Mark
Thanks for that - I knew it had to be a simple answer.. :)
I can see exactly what you mean in terms of the struct key now.. I think the
fact that I link on ID in D/B terms through me abit..
Cheers,
James.
-----Original Message-----
From: transf...@googlegroups.com [mailto:transf...@googlegroups.com]
On Behalf Of Mark Mandel
Sent: 01 August 2008 02:51
To: transf...@googlegroups.com
Subject: [transfer-dev] Re: onetomany - type = "struct" not working
Hi Nando,
Thanks for the example.. It was the order I was doing things that was the problem – alloctating the parent before setting the ‘item’.. Also I expected the getMemento() to reveal a struct for Settings but as Mark points out it’s not stored that way..
Another piece of this excellent framework learnt.. J