rails4,mongoid,使用自定义模型方法查找GTE或LTE查询

时间:2014-09-02 02:22:43

标签: ruby-on-rails mongoid

使用Rails4,mongoid

我定义了total_count

def total_likes
   user_like + customer_like
end

我使用模型自定义方法total_count

找到gte或lte

我如何输入控制器?

class ImageClip

  include Mongoid::Document
  include Mongoid::Timestamps
  include ModelHelper


  field :is_visible, type: Integer, default: 0
  field :is_deleted, type: Integer, default: 0
  field :is_hide, type: Integer, default: 0
  field :user_id, type: Integer
  field :user_likes, type: Integer, default: 0
  field :customer_like, type: Integer, default: 0


  mount_uploader :media_url, MuseUploader


  def total_likes
    likes + amusing_likes
  end 

我找到了

    ImageClip.gte(total_likes: 10)

我找到了解决方案

    ImageClip.where("(this.user_likes + this.customer_like) > #{LIKE_GTE}")

0 个答案:

没有答案