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

  • Home
  • SEARCH
  • 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 6975397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:21:46+00:00 2026-05-27T17:21:46+00:00

Alright so I have a simple has_many :through relationship in Rails 3.1 class Event

  • 0

Alright so I have a simple has_many :through relationship in Rails 3.1

class Event < ActiveRecord::Base
  has_many :invites

  [...]
end

class Account < ActiveRecord::Base
  has_many :invites
  has_many :events, :through => :invites

  [...]
end

class Invite < ActiveRecord::Base
  belongs_to :account
  belongs_to :event

  [...]
end

To get all of user’s events I do

@events = current_account.events

How can I get the record that joined the two tables (ie. the invite row) without running a query for each event? Or at least one column from the Invite record I need to reference?

Using :include => :invites includes ALL invites for each event. I just need the one the join was done on. I scoured Google and couldn’t find anything. I feel like this should be a pretty straightforward thing to do. What am I missing?

  • 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-27T17:21:47+00:00Added an answer on May 27, 2026 at 5:21 pm

    Just fetch them from the other side:

    Event
      .includes ( :invites => :account )
      .where    ( :invites => {:accounts => {:id => current_account.id }} )
    

    Be careful, in the where clause the symbols must be plural (table names) whereas in the includes clause the symbols refer to associations (plural if has_many, singular if belongs_to). BTW, your Invites model should be singular (Invite) according to rails conventions.

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

Sidebar

Related Questions

I have a pretty simple HABTM set of models class Tag < ActiveRecord::Base has_and_belongs_to_many
Alright, I have a fairly simple design. class Update(models.Model): pub_date = models.DateField() title =
Alright, I have a simple boolean at the top of this class, standing. In
Alright simple question I have integriters like 5 188 4634 And they all need
Alright, this might be simple but I dunno how to do it! I have
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
Alright I have a question that seems simple but I haven't been able to
Alright, I have a simple java applet with two buttons and a screen. Both
Alright so I have a plugin for Redmine (Rails Engines.) The plugin uses the
This sounds simple, and probably is... Alright, so I have two tables, users and

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.