Skip to content

Instantly share code, notes, and snippets.

@Ross-Hunter
Last active August 29, 2015 14:02
Show Gist options
  • Save Ross-Hunter/f2539f3e2fd09ad4eb5c to your computer and use it in GitHub Desktop.
Save Ross-Hunter/f2539f3e2fd09ad4eb5c to your computer and use it in GitHub Desktop.
##Class
class User
has_one :profile # inverse_of :profile not necessary in 4.1+
end
class Profile
belongs_to :user # inverse_of :user not necessary in 4.1+
end
##Migration
class AddUserRefToProfiles < ActiveRecord::Migration
def change
add_reference :profile, :user, index: true # adds user_id to profile table
end
end
user.profile
profile.user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment