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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:57:07+00:00 2026-06-01T00:57:07+00:00

I am setting up a has_many :through relationship on my Rails 3.2 app. I

  • 0

I am setting up a has_many :through relationship on my Rails 3.2 app. I have most everything working, except that I’m not sure how to add values to attributes on the join table when relationships are created.

Here are the models (notice the source_id on the Checkins table):

create_table "users", :force => true do |t|
  t.integer  "name"
  t.datetime "created_at", :null => false
  t.datetime "updated_at", :null => false
end

create_table "checkins", :force => true do |t|
  t.integer  "user_id"
  t.integer  "location_id"
  t.integer  "source_id"
  t.datetime "created_at", :null => false
  t.datetime "updated_at", :null => false
end

create_table "locations", :force => true do |t|
  t.string   "name"
  t.datetime "created_at", :null => false
  t.datetime "updated_at", :null => false
end

Here’s the relationship setup:

class User < ActiveRecord::Base
  has_many :checkins
  has_many :locations, :through => :checkins
end

class Location < ActiveRecord::Base
  has_many :checkins
  has_many :users, :through => :checkins
end

class Checkin < ActiveRecord::Base
  belongs_to :location
  belongs_to :user
end

I’m using these instructions (in essence) to loadi a User and Location and create the relationship with a Checkin:

source_id = 10
@user = User.first
@location = Location.first
@user.locations << @location

So, my question is, how do I also add a source_id value to the Checkins table when using this line:

@user.locations << @location

I’m also open to suggestions on a better process for creating new User Checkins with this relationship than what I have above (I’ve seen the create and build methods used, but none seemed to work for me)

  • 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-01T00:57:08+00:00Added an answer on June 1, 2026 at 12:57 am

    Create a Checkin object directly.

    checkin = Checkin.new user: @user, location: @location, source_id: source_id 
    checkin.save
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self join through an intersect table in an app I'm working
I am setting up a simple has_many through relationship. I was wondering if there
I have a rails app that is tracking social data. The users are going
Suppose I have posts, which have many categories through categorizations. Suppose that I add
Im having a bit of an issue setting up a Rails has_many :through :polymorphic
I have problems setting the focus on an input element that has been created
I am setting up a many to many relationship using the :through method and
I have a for loop that cycles through the number of elements that the
I have the following models class Project < ActiveRecord::Base has_many :project_members has_many :members, :through
I have a DataMapper many to many relationship, friends, that needs to be kept

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.