My client enters Ideas, and attaches a Conviction rating (1 to 5) to each. Though he can change the Conviction rating, he wants the history of Conviction ratings available. No problem:
class Idea < ActiveRecord::Base has_many :convictions, :dependent => :destroy end class Conviction < ActiveRecord::Base belongs_to :idea end Conviction has the field 'rating', so when I need to display the latest value with the rest of the idea I just use @idea.convictions.last.rating Now I want to search for the set of ideas having a given value, or set of values, for their latest Conviction.rating. Here's where my weak background in databases and SQL is exposed, I'm not sure what to do. While I'm searching for the answer in my books and online, I thought I would throw it out in case it's obvious to someone. My first thought was to hack the database and add a conviction_rating field to Idea and keep it synchronized with the latest Conviction.rating, making the search trivial, but I hate to give up a teachable moment. And the database will be small so performance is not an issue. Thanks, Scott --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
