使用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}")