belongs to

suggest change

A belongs_to association sets up a one-to-one connection with another model, so each instance of the declaring model “belongs to” one instance of the other model.

For example, if your application includes users and posts, and each post can be assigned to exactly one user, you’d declare the post model this way:

class Post < ApplicationRecord
  belongs_to :user
end

In your table structure you might then have

create_table "posts", force: :cascade do |t|
  t.integer  "user_id",  limit: 4
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActiveRecord Associations:
*belongs to

Table Of Contents
10ActiveRecord Associations
55CSV