拙速メモ

- dogxiの犬のランキングの部分ではまったのでメモ
- 犬は 直近10日間のランキング、直近30日間のランキングなど、複数の複数のランキングを持つ、 dog has_many ranking のアソシエーション
  has_many :user_rankings, :dependent => :destroy
- デフォルトは直近30日のランキングなので、全10日間のランキングのインスタンスを生成せずに、直近30日間のrankingだけeager loadしたい

- has_oneのconditionを動的に設定できないか、検討したがうまくいかない
>参考: dynamic condition for has_one and eager loading issue - Ruby Forum 
http://www.ruby-forum.com/topic/170709

- 解決方法 => has_oneではconditionを指定せず、find時に指定する
 has_many :user_rankings, :dependent => :destroy
 has_one :current_user_ranking, :class_name => 'UserRanking', :foreign_key => :user_id

- 検索時にconditionで絞ってやる

 dogs = Dog.find(:include    => :current_user_ranking,
                 :conditions => ['user_rankings.ranking_id=?', ranking_id])
- これで dogs[0].current_user_ranking で取れる。

** ついでに [#x3f3606d]

- will_paginate で includeがうまく動作しない、とどこかのブログにあったけど、僕が試したところはうまくいった。バージョンは2.3.6。

#blikifooter(志田)


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

アークウェブのサービスやソリューションはこちら