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