开发者

return objects with no associated data

开发者 https://www.devze.com 2023-01-20 16:19 出处:网络
class Game开发者_StackOverflow < Event has_many :statistics, :dependent => :destroy ... end class Statistic < ActiveRecord::Base
class Game开发者_StackOverflow < Event  
  has_many :statistics, :dependent => :destroy

  ...
end

class Statistic < ActiveRecord::Base
  belongs_to :game
end

I want to make a named scope that only returns games that have no statistics.

Thanks


Try

named_scope :no_statistics, :include => :statistics, :conditions => ['statistics.id IS NULL']

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号