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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:03+00:00 2026-06-14T13:51:03+00:00

I have two models. One is an Item model and the other is an

  • 0

I have two models. One is an Item model and the other is an Event model.
What I am needing to do is this:

An Item has to be “checked out” to an Event. The Event will show all Item that are apart of said event. Once event is over, user will check the Item back in. You should still be able to see all items that were apart of said event.

This is how my current models are:


Item Model:

class Item < ActiveRecord::Base
   has_and_belongs_to_many :events
end

Event Model:

class Event < ActiveRecord::Base
   has_many :items
end

I read elsewhere I could have a Model like this that I can use the :though with. This Model would then have all the items that each event has.

EventList

class EventList < ActiveRecord::Base
   belongs_to :item
   belongs_to :event
end

I would like the URL routes to look like:

domain.com/Event/:id/items/

domain.com/Event/:id/items/(checkedin or checkedout)

Is this the correct way of doing things? Should I have another table and use the :though => name for this particular issue?

  • 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-06-14T13:51:04+00:00Added an answer on June 14, 2026 at 1:51 pm

    You are mixing the two up a little bit. If your using has_and_belongs_to_many both models should define it as that. ie.

    Item Model:
    
    class Item < ActiveRecord::Base
      has_and_belongs_to_many :events
    end
    

    Event Model:

    class Event < ActiveRecord::Base
       has_and_belongs_to_many :items
    end
    

    If you want to use a :through table you define both with just has_many.

    As for which one you should use. They are both correct. The link below explains when to use either one. (Basically if you want to do stuff with the join table use the :through way, otherwise has_and_belongs_to_many is fine)

    http://guides.rubyonrails.org/association_basics.html#choosing-between-has_many-through-and-has_and_belongs_to_many

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

Sidebar

Related Questions

I have two models, one is Group, the other Item. A group has many
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have two models, one a vanilla Django model, another an unmanaged model wrapping
I have two models. one is brand and another is product_detail. brands table has
I have an STI-based model called Buyable, with two models Basket and Item. The
Say I have two models and one belongs to another. Now normaly you would
I have two models, A and B, and one light, L. I would like
I have two models that are associated with each other. Customer has_one :primary_contact And
If I have two models that are guaranteed to have a one-to-one correspondence, i.e.
I have a simple has_one/belongs_to relationship between two models. This is a new association

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.