2012-06-25 1 views

답변

1

내가 요금을 추적하고 싶었다면, 나는이

class Store < ActiveRecord::Base 
    has_many :rates, :order => 'applied_on desc' 
    has_one :actual_rate, :class_name => 'Rate', :order => "applied_on desc" 
    scope :with_rate_pc, lambda { |rpc| includes(:rates).where("rates.pourcentage = ?", rpc)} 
end 

class Rate < ActiveRecord::Base 
    belongs_to :store 
end 

는 그런 다음

Store.first.rates #to get all past rates 
Store.first.actual_rate #to get the last rate 

편집 할 수 할 것이다 : 당신을 수 있다는 Store에 범위를 추가 쓰기 :

Store.with_rate_pc(7%) 
+0

만약 내가 특정 세금 ra로 상점을 나열한다면 테? 예 : Store1과 Store2의 세율이 7 %라면? – LearningRoR

+0

니스, 고마워요. – LearningRoR

관련 문제