Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:21:57+00:00 2026-06-06T17:21:57+00:00

I have a users table and a blocked_users table. users has all my authentication

  • 0

I have a users table and a blocked_users table. users has all my authentication data, site preferences, etc, and blocked_users has a source_id and a target_id.

I would like to return a collection of all users that a user has not blocked and that have not blocked the current user.

Right now I have the following code which I execute by calling @user.available_users but it executes three queries. Is there some way to make this a single query?

class User < Sequel::Model

  one_to_many :blocked_users,     :key=>:source_id
  one_to_many :blocked_by_users,  :key=>:target_id, :class => BlockedUser

  def block_user(id)
    BlockedUser.create({source_id:self.id, target_id:id})
  end 

  def blocked_user_ids
    self.blocked_users.map{|bu| bu[:target_id]}
  end 

  def blocked_by_user_ids
    self.blocked_by_users.map{|bu| bu[:target_id]}
  end 

  def available_users
    User.exclude(:id=>self.blocked_users.map{|bu| bu[:target_id]}).exclude(:id=>self.blocked_by_users.map{|bu| bu[:target_id]})
  end 
end

I added the following method to my User class:

  def test_avail
    User.exclude(:blocked_users=>self).exclude(:blocked_by_users=>self)
  end 

1.9.3p0 :001 > User.all.first.test_avail
   INFO - (0.000732s) SELECT * FROM `users`
Sequel::Error: invalid association class User for association :blocked_users used in dataset filter for model User, expected class BlockedUser
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:21:59+00:00Added an answer on June 6, 2026 at 5:21 pm

    Using filter by associations support is probably easiest:

    def available_users
      User.exclude(:blocked_users=>self).exclude(:blocked_by_users=>self)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have users table. There are three other tables: developers, managers, testers. All of
I have a 'users' SQL table structure like this (the ID is randomly generated
I have users' table users , where I store information like post_count and so
i have users table has id field and the friendship table frienduser has friend1id
I have users table, it has id, name last name I have a linq
I have a users table that has the following fields: userid, phone, and address
I have a USERS table like this USERS user_id | username 1 tom 2
I have a users table which I want to display like the Stack Overflow
I have a Users table, which has a Unique constraint on the username (for
I have users table and want to SELECT some rows by bitmask criteria. I'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.