2012-01-19 103 views
-2
  1. AppScreenshot軌HAS_MANY範圍

    class AppScreenshot < ActiveRecord::Base 
        include Cacheable 
        belongs_to :app 
    
        model_cache do 
        with_key 
        end 
    
        scope :available , where(["state > ? and is_icon = ? ",0,0]) 
    
    end 
    
  2. 應用:

    class App < ActiveRecord::Base 
        include Cacheable 
        #acts_as_cached :ttl => 30.minutes 
    
        has_many :apk_files 
    
        has_many :app_screenshots.available 
    
    end 
    

爲什麼has_many :app_screenshots.available

回答

0

:app_screenshots只是一個Ruby符號,所以你不能像這樣調用它的方法。

我認爲像has_many :app_screenshots, :conditions => 'state > 0 and is_icon = 0'

應該在你的情況下工作。

0

如果您執行1.AppScreenshot和2.App :,它會拋出錯誤信息,因爲您不能這樣調用。