从非阻止用户获取帖子 [英] Fetch posts from non blocking users

查看:82
本文介绍了从非阻止用户获取帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从用户那里获取一些阻止我"的帖子.Se型号如下:

I'm trying to fetch some posts from users that isn't blocking "me". Se models below:

User
  id
  username
  ....

Post
  id
  user_id
  content
  ...

Blockings
  blocker_id
  blocked_id

我需要从所有用户处获取没有阻止我的帖子.

I need to fetch posts from all users that isn't blocking me.

我获取所有带有以下内容的帖子:

I fetch all posts with:

@posts Post.all

但是我如何将它们结合在一起.

But how do I joins this together.

SELECT * FROM posts WHERE "posts.user_id isn't blocking me"

我有一个名为 current_user 的助手,该助手返回当前登录的用户"me".

I have a helper called current_user that returns the current logged in user "me".

推荐答案

使用SQL的一种方法是:

A way to do it with SQL would be:

select *
  from post
  where user_id not in 
    (select blocker_id 
    from blockings
    where blocked_id = 1);

只需将数字id替换为变量.

Just replace the numerical id with the variable.

SQL提琴

这篇关于从非阻止用户获取帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆