Skip to content

Instantly share code, notes, and snippets.

@Ross-Hunter
Created June 4, 2014 19:19
Show Gist options
  • Save Ross-Hunter/43b85dd2af1d70bad97a to your computer and use it in GitHub Desktop.
Save Ross-Hunter/43b85dd2af1d70bad97a to your computer and use it in GitHub Desktop.
##Class
class User
has_one :profile
has_one :avatar, through: :profile
end
class Profile
belongs_to :user
has_one :avatar
end
class Avatar
belongs_to :profile
end
##Migration
class AddAvatarRefToUsers < ActiveRecord::Migration
def change
add_reference :avatar, :profile, index: true
add_reference :profile, :user, index: true
end
end
user.avatar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment