I haven't seen anything in this community that relates to this, but if this topic has been mentioned before, please point me to the appropriate post(s). The code in my post applies to release candidate 1 of Rails 1.2.
I'm developing an application that is designed to keep track of fan-made videos. One of the associations in the data model is a many-to-many association between
However, there's some additional attributes that need to be stored in that association. Multiple
s can collaborate on multiple
s, and a subset of those members will be
of the video -- e.g. have the power to change attributes of the video, add/remove collaborators, and so forth. So I've broken up the many-many association into two one-to-many associations using Rails'
To summarize:( Video, Member, and VideoMember class definitionsCollapse )
This was all well and good until I decided to add some additional associations onto
to make things more convenient:( Video class definitionCollapse )
This works to read records, but it won't write records properly. For example:( Code snippetCollapse )
won't be properly set.
The first way I thought of fixing this was to use the
callback to set
, but it seems that association callbacks don't work on
does not generate
The only satisfactory workaround I've found so far is to create a new class for the join entity in which the appropriate callbacks get placed:( VideoOwnerRecord class definitionCollapse )
...and change the definition of
to( Video class redefinitionCollapse )
Similar changes apply to
This gets me the behavior I want, and I can live with this, but I'm wondering if anyone knows a better way to do what is basically specifying different conditions on different associations using the same join model. I'm open to any suggestions, including changing the data model for a cleaner representation (though I'd rather that be the last option :) )