I'm a big fan of database denormalization like this. You said that it's a small app, so performance probably usn't that important, but while we're teaching let's talk about why your idea is right.
To start with: since Ideas have many Convictions, you are adding the column to the smaller of the two tables, possibly saving a lot of space in a large database. You also save doing a join everytime you want to know the current state, and avoid either an insert expensive index or a select expensive scan to find the current item. ActiveRecord doesn't natively expect denormalizations like this. If you were an Oracle guy you would do it with a view, but the great thing about AR is that you can create this behavior by overriding the default attribute accessors, keeping all the logic in the app. On Oct 10, 2009, at 3:01 PM, Scott Olmsted <solms...@gmail.com> wrote: > At 02:27 PM 10/10/2009, Kerry wrote: >> Another way to do this would be to have two separate tables. One with >> the history and one with just the current conviction. You would >> probably >> save each new record into both tables at the same time so your >> history >> has all the records, including current, to make easy history lookup. > > Since there is only one Conviction field of interest, > Conviction.rating, I could just add that field to Idea, rather than > keep it in its own table. Oops, I'm back to my original idea! Maybe > it wasn't so bad after all. > > Thanks, > > Scott > > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list sdruby@googlegroups.com http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---