rails:3467
From: OZAWA Sakuro <sakuro@2...>
Date: Wed, 25 Aug 2010 21:27:31 +0900
Subject: [rails:3467] Re: has_one の検索について
さくです。 2010/8/25 OZAWA Sakuro <sakuro@2...>: >> Q2:以下で検索対象を「最新の注文」に限定するにはどう記述すれば良いですか? >> Customer.all(:include => "order", :conditions => ["orders.cost > ?", 500]) > > 挑戦中。 ↓SQL的にはこうなるんでしょうか。 SELECT * FROM ( SELECT * FROM orders GROUP BY customer_id HAVING MAX(created_at) ) AS latest_orders_by_customer WHERE cost > 500; ↓こうじゃないですよね。 SELECT * FROM orders WHERE cost > 500 GROUP BY customer_id HAVING MAX(created_at); -- OZAWA Sakuro "The future will be better tomorrow." --Dan Quayle -- ML: rails@r... 使い方: http://QuickML.com/
3465 2010-08-25 04:54 [naopontan@g... ] has_one の検索について 3466 2010-08-25 11:57 ┗[sakuro@2... ] -> 3467 2010-08-25 14:27 ┗[sakuro@2... ] 3472 2010-08-26 04:41 ┗[naopontan@g... ]