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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:47:37+00:00 2026-05-16T01:47:37+00:00

I have events and users/teams. class Event has_many :users, :through => :registrations end class

  • 0

I have events and users/teams.

class Event
  has_many :users, :through => :registrations
end
class User
  has_many :events, :through => :registrations
end
class Registration
  belongs_to :users
  belongs_to :events
end

When I register a user, I’m connecting them to the event like so:

@event.users << @user

Does this implicitly create the Registration object for the user/event? I’ve put a :goal_amount column in my Registration migration, and I would like to be able to set the :goal_amount when the Registration is created. Do I need to explicitly create a Registration (ie: Registration.create(:user_id => @user.id, :event_id => @event.id, :goal_amount => params[:goal_amount]) to make this happen?

  • 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-16T01:47:37+00:00Added an answer on May 16, 2026 at 1:47 am

    Yes, adding a user to an event automatically creates the relation object.
    And yes you must manually create the relation if you wish to add that parameter in the middle table.

    One solution to make it look cooler would be to create a add_user method in the event object.

    def add_user user, goal_amount
        Registration.create({
            :user => user,
            :event => self,
            :goal_amount => goal_amount)
        })
    end
    

    Then you just have to call

    @event.add_user @user, 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a freelance web application that lets users register for events. In my
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a table that functions as an event log and stores the users
I have a simple query in php on oracle: $query='select u.username,u.lastname,u.firstname,c.event,c.reason from users u,
If have an event that fires when a user clicks outside of text field,
On page1.php I have a click event that causes the user to be redirected
I have a javascript that runs using the onchange event when a user enteres
I have got two models, User and Event. I need two kind of relationship
In the application I'm building, I want to have Events. People can then register
I have two tables: events and events_actions events columns: event_id user_id event_name events_actions columns:

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.