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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:43:08+00:00 2026-05-21T06:43:08+00:00

I have a User model that has billing_id. I have Order model that runs

  • 0

I have a User model that has billing_id. I have Order model that runs transactions with a payment gateway which returns a billing id I’d like to save into the billing_id column on the User model. I think I am getting the basics of MVC architecture mixed up.

I am under the impression that UsersController and OrdersController update data of their respective tables. Does that mean that if I have something returned from OrdersController such as a billing id, there is no other way of saving that billing id into a billing_id column in User model? Thanks and sorry if this is extremely rudimentary. 🙂

Also, I thought a possible solution might be to somehow pass in the return value via ApplicationsController into UsersController to save into User table. Is this possible?

  • 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-21T06:43:09+00:00Added an answer on May 21, 2026 at 6:43 am

    Your user orders table should have an instance of user_id, as a user can have multiple orders.

    You can do this by creating a migration:

    rails g migration add_user_id_to_orders order_id:integer
    rake db:migrate
    

    Your models will then look like:

    class User < ActiveRecord::Base
      has_many :orders
    end
    
    class Order < ActiveRecord::Base
      belongs_to :user
    end
    

    You need a link between the two (order_id) otherwise they would have no knowledge of each other. This is known as a foreign key.

    When things are set up this way, you can get the users by doing:

    User.find(1).orders
    

    And you can find the user information from an order by doing:

    Orders.find(1).user
    

    I hope this helps.

    EDIT:

    Orders.find(ORDER_ID).user.update_attributes(:billing_id => BILLING_ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a User model that :has_many other models like Documents, Videos, Posts
I have a model that has a ForeignKey to the built-in user model in
Say I have a model called User that has the following parameters: favorite_color, favorite_animal,
I have a model that holds user address. This model has to have first_name
I have a user model on which I check to make sure that the
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I have a User model that has many fights. Fight belongs to User. There
I have an user view model that has the following properties: public User user;
I have two models: User MentoringRelationship MentoringRelationship is a join model that has a
I have a rails model User that has name , email and hash fields.

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.