mardi 13 octobre 2020

Is there a way to use a where statement with multiple tables?

I have three tables

Table name: follows
#
#  id         :bigint           not null, primary key
#  following  :bigint
#  requestor  :bigint
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  user_id    :bigint
#
# Indexes
#
#  index_follows_on_user_id  (user_id)
    belongs_to(
        :user,
        class_name: 'User',
        foreign_key: 'user_id',
        inverse_of: :follows
    )
User
has_many(
    :follows,
    class_name: 'Follow',
    foreign_key: 'user_id',
    inverse_of: :user
  )

Post
belongs_to(
        :user,
        class_name: 'User',
        foreign_key: 'user_id',
        inverse_of: :posts
    )

The requestor column takes a user.id.

I would only like to show the Posts where the requestor attribute == current_user.id. Am I only able to do this with a join or is there a way to do this with a where statement?

Aucun commentaire:

Enregistrer un commentaire