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