HABTM population from text fields

Hi. I'm having problems wrapping my head around the use of HABTM. I just haven't found a good enough reference for dealing with HABTM-linked models, and my business logic is full of them.

In this case, I have a model Initative and a model called Reference for associating one or more reference documents to an Initative. Any Reference document could also be referenced by any number of Initatives. So Initative has objects/columns Initative_ID and also Ref_Num:String. I have declared HABTM in each model.

I need a straighforward way for a user to enter associated documents from the context of an Initative record form. I would think that an editable dropdown would be one way, which would allow the user to select a Reference already in the database or allow them to enter a new one. I also would settle for some version of a text field or text area with a "Add Reference" button. I would even consider a popup form with some version of these controls.

Being that all of the HABTM references I have seen seem to be really checkbox-focused, I haven't really seen anything that gives me a good idea how to go about this. I have done similar things in Access and Notes, but can't quite figure out the HABTM syntax well enough to do it in Rails.

Help?

Hello,

Start by reading the following articles: http://blog.hasmanythrough.com/2006/4/20/many-to-many-dance-off http://blog.hasmanythrough.com/2007/1/15/basic-rails-association-cardinality

You cannot have a many-to-many relationship between Initiative and Reference if you put your reference foreign key into your Initiative table !

Regards,

Stijn http://www.xaop.com

Oops, that was actually just a massive typo on my part.

The Reference model has the field called Reference_ID (:integer) and Ref_Num (:string). The join table initatives_references just has Reference_ID, Initative_ID.

Thanks.

Stijn Pint wrote: