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 7583771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:45:46+00:00 2026-05-30T18:45:46+00:00

class Users < ActiveRecord::Base has_many :meetings, :through => :meeting_participations has_many :meeting_participations end class Meetings

  • 0
class Users < ActiveRecord::Base
  has_many :meetings, :through => :meeting_participations
  has_many :meeting_participations
end

class Meetings < ActiveRecord::Base
  has_many :users, :through => :meeting_participations
  has_many :meeting_participations
end

class MeetingParticipations < ActiveRecord::Base
  belongs_to :user
  belongs_to :meeting

  scope :hidden, where(:hidden => true)
  scope :visible, where(:hidden => false)
end

hidden is an extra boolean column within the m2m association table. Given some Users instance current_user, I want to do

current_user.meetings.visible

which will retrieve a collection of Meetings for which the user is a participant where the hidden column is false. The closest I have gotten is adding the following scope to the Meetings class

scope :visible, joins(:meeting_participations) & MeetingParticipation.visible

The scope does filter the Meetings against the MeetingParticipations table, however there is no join/condition against the MeetingParticipations table related to current_user.

The issue with this is, if current_user and another_user are both participants for some Meetings instance, a Meetings record in the result set will be returned for each participant that has hidden set to false. If current_user has true set for hidden for all Meetings, if another_user is a participant in any of those same Meetings with hidden set to false, those Meetings will appear in the Meetings.visible result set.

Is it possible to have a scope as I’ve mentioned above which will properly join on the User instance? If not, can someone recommend a solution to this?

  • 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-05-30T18:45:47+00:00Added an answer on May 30, 2026 at 6:45 pm

    This is my solution for your problem:

    class User < ActiveRecord::Base
      has_many :meeting_participations
      has_many :meetings, :through => :meeting_participations do
       def visible
         where("meeting_participations.visible = ?", true)
       end
      end
    end
    

    @user.meetings.visible

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this relationship : class Organization < ActiveRecord::Base has_many :users end class User
class Exercise < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :exercises end
Models: class User < ActiveRecord::Base has_many :attendances has_many :courses, :through => :attendances end class
class Company < ActiveRecord::Base has_many :users end The user hits on Company->Users href link
I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have the following class: class Group < ActiveRecord::Base has_many :users belongs_to :leader, :foreign_key
I am using Rails 2.3.5. Class User < ActiveRecord::Base has_many :phones end class Phone
Can't wrap my head around this... class User < ActiveRecord::Base has_many :fantasies, :through =>
I have 2 models: Video: class Video < ActiveRecord::Base belongs_to :user has_many :thumbnails attr_accessor
I have this: class User < ActiveRecord::Base has_many :serials has_many :sites, :through => :series

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.