Wow, thanks so much for the detailed reply and the extra help.
I hadn't been back to this post for a few days, as I've been working
on this when I could and studying the wheels docs a lot. I arrived at
a very similar approach...although, I think I left a couple of things
out, that may or may not come back to haunt me later heh.
Basically I was already onto nested properties before I had posted.
My main stumbling block at that time though, was how to populate the
form for new majors. Basically I was missing the bit where you create
the majorContacts as an array of obj's on the new() controller.
Finally worked that out... although I did:
{{{
<cfset var newMajorContacts =
[ model("majorcontact").new(type="administrative"),
model("majorcontact").new(type="program") ] >
<cfset major = model("major").new(majorcontacts = newMajorContacts)>
}}}
Then for the view, in my _major partial I just did:
{{{
<cfloop from="1" to="#ArrayLen(major.majorcontacts)#" index="i">
#select(label="#major.majorcontacts[i].type# contact",
objectName="major", association="majorcontacts",
position=i, property="contactid", options=allContacts)#
</cfloop>
}}}
...kind of pieced that together from examples in the docs on the
select helper... at one point I had a keys attribute on there (from
the hasManyCheckBox example) but worked out that wasn't needed pretty
quickly.
...a couple of other differences from my approach:
- I didn't add hidden fields for type on the form. Seems to be
working as expected without that, as the obj's are getting the correct
type.
- for the update action, I found that with between the nested
properties setup and the form/select, I didn't need to instantiate the
majorcontacts separately, as long as I include majorcontacts on the
find like so:
{{{
<cfset major = model("major").findByKey(key=params.key,
include="designation,college,degree,majorcontacts")>
}}}
...after that, update is just like create basically. Oh and if anyone
wonders about my using key=params.key there... I am in the habit of
setting a key attribute on startformtag like key="#
major.id#". That
way, I have the findByKey factored out to a filter function as well,
and filter anything through that which needs to get a specific major
(I love filters!)
- already had the contacts, designations, colleges, etc. drop-down
data already factored out to a filter method (did I mention that I
love filters...they are the bees knees).
Overall though, approach is the same, and your write-up has given me
some additional points to think about like the ordering, hidden fields
for type etc. So I will definitely work through those as well.
Thanks again for the great reply :)