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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:03:57+00:00 2026-05-13T15:03:57+00:00

I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model

  • 0

I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model (:name)

Then I created two join tables -> UsersInterests and EventsInterests; each not containing a primary key and only comprised of the user_id/interest_id and event_id/interest_id respectively.

I’m trying to use ActiveRecord to query a list all the events where the interest.id of EventsInterests= interest.id of UsersInterests

I’m using has_many and belongs_to relationships with the Nested Loop Plugin

My models look like so =>

user.rb

has_many :users_interests
has_many :interests, :through => :users_interests

event.rb

has_many :events_interests
has_many :interests, :through => :events_interests

interest.rb

belongs_to :users , :through => :users_interests
belongs_to :events , :through => :events_interests

users_interests.rb

belongs_to :users
belongs_to :interests

events_interests.rb

belongs_to :interests
belongs_to :events

If the @user= User.find(1), How would I query the events a user would be interested in?

I came up with this =>
@events.find(:all, :conditions => EventsInterests.interest_id = UsersInterests.interest_id) ??

but I get the error

undefined method `interest_id' for UsersInterests(user_id: integer, interest_id: integer):Class

umm..wtf? any help guys….I’ve been at this for like 4 days

  • 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-13T15:03:58+00:00Added an answer on May 13, 2026 at 3:03 pm

    First, hop into the console and make sure all of your relationships work:

    User.first.events
    User.first.interests
    Events.first.users
    Interests.first.users
    Interests.first.events
    # ... and so
    

    Just to clarify, a User lists his Interests, and you want to get a list of the Events matching those interests?

    User.first.interests.collect { |interest| interest.events }.uniq
    

    Not particular efficient, but effective and easy to comprehend.

    You could use User.first.interests_singular_ids to get the ids and pass that to a find() with interest_id IN(...) that list, too. I’m not sure how much faster it would be, though.

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

Sidebar

Related Questions

Hi ok I have two tables one called Login and one called User there
I have a naked rails 3 app with one model, generated using rails g
I have a django project that I have been using for a while, but
I've just read about MVC3's new CompareAttribute that you can apply to a model's
I use Mongoid and Fabrication gems. I have switched to Mongoid.rc7 from beta20 and
I have to call the web service using java script? e.g. I'm creating one
Trying to use the getDependentRowset in a ZF application. I have the following relationship
I am wondering what is considered best practice when passing info from a controller
I am trying to enter a foreign key value along with data collected from
Maybe that's not exactly the solution i need, but this is what i want

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.