use plain Ruby memoization to fix deprecation (closes #121)

This commit is contained in:
wvengen 2013-09-18 22:45:57 +02:00
parent 6b0146eb95
commit c7f28a3b5c
2 changed files with 41 additions and 41 deletions

View file

@ -1,6 +1,5 @@
# encoding: utf-8
class Article < ActiveRecord::Base
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
# Replace numeric seperator with database format
localize_input_of :price, :tax, :deposit
@ -44,11 +43,12 @@ class Article < ActiveRecord::Base
# If the article is used in an open Order, the Order will be returned.
def in_open_order
order_articles = OrderArticle.all(:conditions => ['order_id IN (?)', Order.open.collect(&:id)])
order_article = order_articles.detect {|oa| oa.article_id == id }
order_article ? order_article.order : nil
@in_open_order ||= begin
order_articles = OrderArticle.all(:conditions => ['order_id IN (?)', Order.open.collect(&:id)])
order_article = order_articles.detect {|oa| oa.article_id == id }
order_article ? order_article.order : nil
end
end
memoize :in_open_order
# Returns true if the article has been ordered in the given order at least once
def ordered_in_order?(order)