0
此方法從數據庫返回一些記錄。在rails上添加紅寶石查詢
def wall_record(ref_id,followers_record,pid,sd_pid)
@Wp_rec=Wallpost.select('Wp.id as Pid,Wp.*,Wi.id as Iid,Wi.imagename,Wv.videourl,U.firstname,U.username')
@[email protected]_rec.where('Wp.id > ? ', pid) if pid.present? # pid->PostId
@[email protected]_rec.where('Wp.id < ? ', sd_pid) if sd_pid.present? # sd_pid -> Scroll down
@[email protected]_rec.where('Wp.posted_by IN (?) ', followers_record) if followers_record.present?
@[email protected]_rec.joins('Wp INNER JOIN `epoker_wallimages` as Wi on Wi.wallpost_id = Wp.id')
@[email protected]_rec.joins('INNER JOIN `epoker_users` as U on U.id = Wp.user_id')
@[email protected]_rec.joins('INNER JOIN `epoker_wallvideos` as Wv on Wv.wallpost_id = Wp.id')
@[email protected]_rec.order('Wp.id DESC') if followers_record.present?
@[email protected]_rec.limit(5) #if followers_record.present?
end
現在我想添加MySQL查詢 - >where((Wp.posted_by != 100000 AND post_status = 1) OR (Wp.posted_by = 10000 AND post_status in (1,2)))
我怎麼能做到這一點嗎?
謝謝@okliv它的工作。 – Gagan
第二種方法可能使您容易受到SQL注入的攻擊,第三種方法更受歡迎,除非您可以絕對確定用戶無法將任意數據放入查詢。 – Slicedpan