0
class Item < AR
has_many :holdings
class Holding < AR
belongs_to :item
ホールディング・モデルは、 'アクティブ' ブール値を有します。
私は、0個のアクティブなホールディングス(関連するホールディングをいくつでも持つかもしれません)を持つ各アイテムを探したいと思います。
SELECT * from items JOIN
(SELECT holdings.item_id, count(ifnull(item_id,0)) AS hcount FROM holdings
WHERE holdings.active = "t"
GROUP BY holdings.item_id
HAVING hcount = 0)
ON items.id = holdings.item_id
が、これは誰もが正しい方向に私を指す0
より大きい数を返しますか?
ありがとう、それはもっと意味があります! – scaney