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

Another basic Rails question: I have a database table that needs to contain references
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have a rails application which is still showing the cachebusting numeric string at
I have a Rails project which I neglected to build tests for (for shame!)
I have a Rails 2.0.2 application running with a postgresql db. The machine will
I have a rails app that I have serving up XML on an infrequent
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I have a rails application where each user has a separate database. (taking Joel
I have a rails application running on a Linux server. I would like to
I have a rails form with a datetime_select field. When I try to submit

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.