Topic: [Solved] Best approach to implement model? (Many-to-Many, polymorphic)
Hi,I'm starting with Rails and I'm developing an app which will sit over this existing model (http://imgur.com/ZuaCm). Although I might apply some changes in the model (legacy stuff, so that is my last option in fact), I'm finding it hard to implement it with Rail's Active Record.
I have Item and Property models (many-to-many relation), whose relation has a Value (1 item has several properties, and a property has a value for that item). Now, to complicate things a little more, an hierarchy of several value types was defined (I've only drawn 1 column in DECIMAL_VALUE and TEXT_VALUE tables, but there are more columns and more tables like those).
So, until now I've created an "ItemValuation", which will be the joint model for Item/Property/Value, and my ideia is to use "has/through" between items and properties. But I don't know how to design the Value part. The idea would be have the value stored in one of the child tables, and have it's ID in the joint table. I've also read about polymorphic associations, which might be used here in that hierarchy (not sure how to use this here).
Another doubt I have is, if keeping this model, which resources need to be nested (item -> property -> value?).
Can someone help here?
Last edited by imnotnot (2012-11-02 12:19:31)