[前][次][番号順一覧][スレッド一覧]

rails:3206

From: Nobuhiro IMAI <nov@y...>
Date: Sat, 12 Sep 2009 09:06:44 +0900 (JST)
Subject: [rails:3206] Re: Active Record での書き方

いまいです。

From: Koichi Shimamura <maf01541_at_nifty.ne.jp>
Date: Sat, 12 Sep 2009 08:40:47 +0900

> @models = ( records = Model.find(:all, :conditions => ["created_at > ?",
> 1.day.ago], :order => 'updated_at desc') ) ? Model.find(:all, :limit =>
> 10, :order => 'updated_at desc') :  records

[] は真なので、常に :limit => 10 の方の結果が返るような気がするのですが、
そんなことありません?

>> Model.find(:all)
=> []
>> Model.find(:all) ? ":limit => 10" : "records"
=> ":limit => 10"
>> Model.create!
=> #<Model id: 1, created_at: "2009-09-12 00:01:41", updated_at: "2009-09-12 00:01:41">
>> Model.find(:all)
=> [#<Model id: 1, created_at: "2009-09-12 00:01:41", updated_at: "2009-09-12 00:01:41">]
>> Model.find(:all) ? ":limit => 10" : "records"
=> ":limit => 10"
--
Nobuhiro IMAI <nov@y...>
Key fingerprint = F39E D552 545D 7C64 D690  F644 5A15 746C BD8E 7106

--
ML: rails@r...
使い方: http://QuickML.com/

[前][次][番号順一覧][スレッド一覧]

      3174 2009-09-02 10:58 [maf01541@n...       ] Active Record での書き方                
      3178 2009-09-03 11:36 ┣[ggb03124@n...       ]                                       
      3181 2009-09-03 13:32 ┃┗[ggb03124@n...       ]                                     
      3180 2009-09-03 11:58 ┣[sakuro@2...         ]                                       
      3184 2009-09-04 03:34 ┃┗[ggb03124@n...       ]                                     
      3185 2009-09-04 05:56 ┃ ┗[ofl@c...            ]                                   
      3189 2009-09-04 13:12 ┃  ┗[maf01541@n...       ]                                 
      3205 2009-09-12 01:40 ┃   ┗[maf01541@n...       ]                               
->    3206 2009-09-12 02:06 ┃    ┣[nov@y...            ]                             
      3208 2009-09-12 02:46 ┃    ┃┗[maf01541@n...       ]                           
      3209 2009-09-12 03:00 ┃    ┗[ofl@c...            ]                             
      3182 2009-09-03 20:43 ┗[nov@y...            ]                                       
      3183 2009-09-03 21:05  ┗[nov@y...            ]