Complex Database Associations

Hi All,

I’m running into some issues with a fairly complex database structure.

I have 4 tables:
Products

  • id
  • name

Productsitems

  • id
  • product_id
  • name

Units

  • id
  • product_id
  • serialnumber

Unitparts

  • id
  • productsitem_id
  • unit_id
  • partnumber
  • serialnumber

What I’m attempting to do is to create a page where, after selecting
which product I’m entering, I get presented with the data entry for a
new unit and the appropriate number of unitparts for that product as
defined by productsitems. The issue is that I need to somehow, in the
view, link the partnumber and serialnumber fields back to the
appropriate productsitem and then to parse them out so that those ids
make it into the database.

In other languages I would simply enumerate my fields and parse the
resulting variable names - is there a simple way to do this in Rails?

Thanks,
Mike