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.
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.
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.