Set Up Has One
When to Use
Schema Setup
schema.table :users do
primary :id, Int64, auto_increment: true
column :name, String
timestamps
end
schema.users.create!
schema.table :profiles do
primary :id, Int64, auto_increment: true
column :user_id, Int64, null: false
column :bio, String
column :avatar_url, String
foreign_key [:user_id], references: :users, references_columns: [:id]
index [:user_id], unique: true
timestamps
end
schema.profiles.create!Define the Relationship
Access the Related Record
Create Related Record
Create Profile for User
Build and Save
Update Related Record
Delete Related Record
Verify It Works
Related
Last updated
Was this helpful?