I am dealing with a legacy db which is limiting my options here.

I have...

class Stockmaster < ActiveRecord::Base
  set_table_name "stockmaster"
  set_primary_key "stockid"

  has_many      :prices

  def wholesale_price(stockid)
    Price.find(:first, :conditions => ["stockid = ? AND typeabbrev = ?",
stockid, "WH"])
  end

  def retail_price(stockid)
    Price.find(:first, :conditions => ["stockid = ? AND typeabbrev = ?",
stockid, "RE"])
  end
end

and

class Price < ActiveRecord::Base
  set_table_name "prices"
  set_primary_key "stockid"

  belongs_to    :stockmaster
end

and my issue is that I have both a 'WH' and 'RE' typeabbrev for each
stockid and I need to make this simpler for a database lookup to print a
prices sheet.

It makes sense to do eager loading of associations here but I cannot
figure out how to change the model for this eager loading since for each
stockid, there are two values (WH/wholesale and RE/retail).

Can anyone toss me a bone here?

Craig


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


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