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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:54:09+00:00 2026-05-13T07:54:09+00:00

I have a rails question that I cannot seem to wrap my head around.

  • 0

I have a rails question that I cannot seem to wrap my head around.

I have an Invite model which will represent a name, address, number of people on the invitation, plus 1 or not, etc.

I also have an Event model which has name, location, and time of the event.

I would like to associate Invites to Events through something like a Schedule. I want to be able to create pre-defined Schedules as collections of Events and then associate an Invite to a specific Schedule.

So far I have the following.

class Invite < ActiveRecord::Base
  belongs_to :schedule
  has_many :events, :through => :schedules

  #a schedule_id column exists in the invites table
end

class Event < ActiveRecord::Base
  has_many :schedules
  has_many :invites, :through => :schedules
end

class Schedule < ActiveRecord::Base
  has_many :events
  has_many :invites
end

If we have Events e1, e2, e3 and Invites i1, i2 and Schedules s1 has e1 and e2' and 's2 has e2 and e3 then I want to be able to associate Invite i1 with Schedule s1 and Invite i2 with Schedule s2.

I can get the Invites to Schedules relationship but the many-to-many Events-to-Schedules along with the Invites is currently confusing me. Any thoughts? Any other ways to think about this?

I ultimately want to be able to say invite.events and event.invites.

  • 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-13T07:54:10+00:00Added an answer on May 13, 2026 at 7:54 am

    This is a little tricky to pull off, but not impossible. However you appear to be missing the join model for Events and Schedules. This is necessary to make the relationship work.

    Also you’ll need this plugin for the nested has_many :through relationship. of Events => Schedules => Invites. Once installed the following relationships will give you your desired effect.

    class Invite < ActiveRecord::Base
      belongs_to :schedule
      has_many :events, :through => :schedules, :source => :event_shedules
    
      #a schedule_id column exists in the invites table
    end
    
    class Event < ActiveRecord::Base
      has_many :event_schedules
      has_many :schedules, :through => :event_schedules
      has_many :invites, :through => :schedules
    end
    
    class EventSchedules < ActiveRecord::Base
      belongs_to :event
      belongs_to :schedules
    end
    
    class Schedule < ActiveRecord::Base
      has_many :event_scheudles
      has_many :events, :through => :event_schedules
      has_many :invites
    end
    
    @s1 = Schedule.create
    @s2 = Schedule.create
    @e1 = Event.create
    @e2 = Event.create
    @e3 = Event.create
    @s1.events << [@e1,@e2]
    @s2.events << [@e2, @e3]
    @i1 = @s1.invites.create
    @i2 = @s2.invites.create
    
    @s1.invites # => [@i1]
    @s1.events  # => [@e1,@e2]
    @s2.invites # => [@i2]
    @s2.events  # => [@e2,@e3]
    
    
    @e1.invites # => [@i1] #not possible without the plugin
    @e2.invites # => [@i1,@i2] #not possible without the plugin
    @e3.invites # => [@i2] #not possible without the plugin
    
    @i1.events  # => [@e1, @e2]
    @i2.events  # => [@e2, @e3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A bit of a newbie question on rails associations. I have a Bug model,
Another basic Rails question: I have a database table that needs to contain references
I have a rails app running on port 3000. The page in question has
Im new to rails and have a question about accessing relations of relations in
I have a question about ruby on rails and the process of assigning variables
Hi I have a question about ruby on rails Apparently I have a statement
I have a prototype question in the context of Ruby on Rails. QUESTION -
I have a question. Devise and mailboxer are installed on my rails app without
I am working on Ruby on Rails rspec testing and I have a question.
I am using haml with my rails application and i have a question how

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.