Robby Russell wrote:
> On Tue, Sep 30, 2008 at 9:13 PM, Anthony E.
> <[EMAIL PROTECTED]> wrote:
>> Something like this:
>> @book.price = $20.00
>>
>> @book.save()
>> @stats.save()
> 
> Anthony,
> 
> Is Book the only model that you'll be doing this for? ...or are there
> other models that will use this historical log of prices?
> 
> There's a few options here. One, you could add method to be called by
> after_save to check the price previously stored with the new one... if
> they are different... add a new entry to the historical log.
> 
> Another option is to not store prices in the Book model and only in
> another table called something like BookPrice.
> 
> book has_many book_prices
> 
> Then you can scope book_prices for current to do something like:
> 
> book.book_prices.current.price  # => get the current price
> 
> book.book_prices.each { |book_price| ... }   # => iterate through all
> book prices
> 
> Anyhow, there's a few options to throw your way. Good luck!
> 
> Cheers,
> Robby
> 
> 
> 

Thanks Robby.

I will be doing this for one model for now, perhaps others down the 
road.

The "Book" model has numeric attributes that I want to save into a 
"statistics" table so I can draw a line-graph over time from it.

Other attributes would be archived as well.

Its sounds to be a before_update would give me access to the current 
price. And I don't want to keep the current price in a stats table 
because that table will eventually grow and slow down the regular query.

book
----------
id
title
price
edition
year

stats
----------
id
book_id
price
edition
year
created_at
updated_at


Ideally sans-rails the stats table would be populated with a trigger 
when the book table is updated.

There book will definitely "has_many :stats" but I don't really want 
that association to be queried every time I get a regular book object, 
only when I build the stats page.


-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to