I am trying to work with objects and better understand how to use them. So far
it has been straight forward when updating/creating/deleting one record at a
time. But I now need to update many records at once is getting a bit tricky.
I simplified version of what I am doing so far is below...
I create an object...
var productBean = variables.storeService.createProductBean(); //Create Product
Bean
Push the data into it using this very useful plugin in CB
getPlugin('beanFactory').populateBean(productBean);//The Magic Bean Machine
and then simply update my DAO via my service like so
variables.storeService.saveProduct(productBean)
my question....
However I am now faced with a situation where I need update several records at
the same time. So my question is how to I handle this with an object? do I have
to repopulate my object in a loop and then do the database updates one at a
time? I can see this causing many issues what if the write fails halfway etc,
and it means writing some sort of array to store all the data while its being
looped over, sounds cumbersome!
Below is how I would have done the update before objects in a procedural manner
if you get what I mean...
<cfloop from="1" to="#FORM.qty#" index="i">
<cfscript>
value = "";
if (i IS 1) {
value = #FORM.value1#;
}
else if (i IS 2) {
value = #FORM.value2#;
}
else if (i IS 3) {
value = #FORM.value3#;
}
else if (i IS 4) {
value = #FORM.value4#;
}
else if (i IS 5) {
value = #FORM.value5#;
}
else if (i IS 6) {
value = #FORM.value6#;
}
else if (i IS 7) {
value = #FORM.value7#;
}
</cfscript>
<cfif NOT value IS "">
<cfquery name="addValue" datasource="dbSource">
INSERT INTO optionValues (value, optionId) VALUES ('#value#', '#optionId#')
</cfquery>
</cfif>
<cfset i = i + 1>
</cfloop>
<cfset success = TRUE>
how do other people do this sort of update using objects, any example, blog
posts, ect would be very useful. Thanks.
:)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326689
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4