For those not familiar with the term CRUD, it stands for “create”, “retrieve” “update” and “delete”. Basically, these are the four (4) basic operations you ever need to do to maintain information.
After a bit of struggling to understand Rails support of many-to-many relationships, whether it is with HABTM (Has And Belongs to Many) or HMT (Has Many Through) as they intersect with ActiveScaffold, I finally was able to determine a reasonable approach to supporting editable many-to-many relationships.
For those interested, HABTM supports only weak entities. This can be, in the majority of cases, all that you really need when tracking a many-to-many relationship; however, there appears to be some consensus that HABTM and weak entities are a Bad Thing. Frankly, while I think some people’s positions are over-stated on the matter of HABTM, it is true that there is some niceness when using with HMT over HABTM. As previously stated, HABTM are weak which means they have no state of their own. The use of HTM (strong entity vis-a-vis join table) allows you to track not just the relationship, but the state of the relationship between the two entities; itself a good thing if you need this.
Ultimately I decided that I wanted to use HTM throughout Kotoba to keep things consistent and provide insurance against future growth. Unfortunately, ActiveScaffold’s support for HTM is only read-only while HABTM is fully editable right out of the box. And unfortunate in that I really want to be able to add words to vocabulary lists, and vocabulary lists to words in a manner that is intuitive and usable. That said, I needed a means of updating the vocabulary_lists_words
join directly from either vocabulary lists or words. Luckily the wonderful developers of ActiveScaffold include some necessary call-backs (e.g. before_update_save
) at the controller level very similar in vein to ActiveRecord’s before_
methods.
What does this mean to you? You can now manage your vocabulary list’s words directly from the vocabulary list. And equally cool, you can just add a word to your vocabulary list as you find them.