Skip to content

Instantly share code, notes, and snippets.

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