Anthony E. wrote:
> Robby Russell wrote:
>> On Wed, Oct 1, 2008 at 4:01 PM, Anthony E.
>> <[EMAIL PROTECTED]> wrote:
>>> have to scan the entire 'prices' table.
>>>
>> 
>> *sniff* I smell premature optimization. ;-)
>> 
>> Seriously, with database indexes... this is doubtful to be an issue.
>> If it's ever an issue you can cache the current price in the book
>> model, but really... I wouldn't be concerned about that for a while.
>> 
>>> I'd rather do it in such a way that it only saves the current price,
>>> year, edition, etc. to a "stats" whenever the book is updated (without
>>> any explicit association).
>> 
>> This is the case either way. Just not convinced you need to cache this
>> in the Book model from the get-go, which is what you're leaning
>> toward.
>> 
> 
> 
> 
> Thanks Robby, you may indeed be correct.
> 
> Is it safe to say your recommendation is to create a model for each 
> statistical attribute I want to archive?
> 
> ie:
> Price
> Year
> Edition
> 
> ...and associate them to the Book via: has_many and then use the most 
> recent as the current price?



I can't get the save to work across the association. The price is coming 
from a backend system un-related to rails so I have got the data itself 
no problem with "get_price" and saving it to self.price is fine...but I 
can't refactor this into saving to another model (ie: prices)

Book < ActiveRecord::Base
has_many :prices
before_save :get_price
after_save :set_price

def get_price
  price = Legacy::Data.new().price
end

At this point my understanding breaks down...how do I save that 
"get_price" value to the "Prices" model?


#brokenzy

def set_price
  @price = self.prices.new
  @price.price = self.price
end

-- 
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