Array and Struct notation in Forms

27 views
Skip to first unread message

Erick - AngelsEye

unread,
Dec 20, 2011, 5:48:49 PM12/20/11
to ColdBox Platform
This may be a CF question and not a CB question, but I can't seem to
find any information on it on Google or in the CB docs.

Having a relationship of many products to 1 order...

Is there a way to setup my form fields so that when I use
populateModel(rc.order), that it will also populate
rc.order.setProducts(array of product model properties) like you use
with "nested_attributes" in Ruby on Rails?

I know I can loop through my form fields and build an array of my
product properties for each product in my form submitted and then set
those using the setProducts() method in my Orders model, but I didn't
know if I was making extra work for myself over just setting the names
on my form fields to a certain notation so that populateModel() works
in this manner.

Any help would be greatly appreciated.

Thanks

Erick

Brad Wood

unread,
Dec 20, 2011, 3:57:14 PM12/20/11
to col...@googlegroups.com
You might find this interesting:
http://objectivebias.com/entry/formutilities-plugin-for-coldbox

With the form utiities set up as a plugin, you can name your form fields in such a way that they are converted into arrays or structs for you.

I don't use populateModel() that comes with ColdBox so I don't know if it will automatically populate composite objects, but that plugin shoud get you going in the right direction.

Thanks!

~Brad

Sent from my ASUS Eee Pad

>--
>You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
>To post to this group, send email to col...@googlegroups.com
>To unsubscribe from this group, send email to coldbox-u...@googlegroups.com
>For more options, visit this group at http://groups-beta.google.com/group/coldbox
>For News, visit http://blog.coldbox.org
>For Documentation, visit http://wiki.coldbox.org
>

Luis Majano

unread,
Dec 20, 2011, 10:13:49 PM12/20/11
to col...@googlegroups.com
Erick, this has been requested for a while now and I would love user input in how to add this functionality?

John Whish

unread,
Dec 21, 2011, 7:02:48 AM12/21/11
to col...@googlegroups.com

I have done something like this a while back using Brian Kotek's form utilities. So the naming of the form fields determines the datatype, and then go from there. My implimentation wasn't generic, but it could be a good starting point.

- sent by a little green robot powered device

Erick Wilson - AngelsEye

unread,
Dec 21, 2011, 8:55:31 AM12/21/11
to col...@googlegroups.com
Yeah, I saw Brian's utility and that might be a good start for jumping off.
I am personally used to the way Rails does nested attributes but honestly if we just used CF notation, it would be something that is familiar to everyone.  That way if the code sees a form variable parentObj.childArray[1].childObjProperty (basically if it sees dots, and braces or even braces with quotes in them), it would assume a structure or an array and parse it out.

I think the biggest key would be allowing populateModel() to take that input structure and assuming the form field names are the same, it would populate the entire relationship across all child objects it finds that matches.

Since I can't do that now, I've got no problem programatically setting all my child properties, but that might be a good CB 4.0 addition that would speed up development even more.  I'd love to help make that happen when you get there, if you need it.

Thanks

Erick Wilson
AngelsEye, Inc
800-690-3740 - Ext. 101
800-690-2089 - Fax
ewi...@angelseyeinc.com
www.angelseyeinc.com

"If you don't know where you are going, any road will take you there." -- Lewis Carroll, Alice in Wonderland

Luis Majano

unread,
Dec 22, 2011, 1:12:22 AM12/22/11
to col...@googlegroups.com
Yes, please, I would love community help here
Reply all
Reply to author
Forward
0 new messages