Created
October 12, 2018 13:58
-
-
Save tyleramos/50ccff7a3f75048e5651989b82f21a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Org has the following columns: | |
# - id | |
# - name | |
class Org < ApplicationRecord | |
has_many :users | |
end | |
# User has the following columns: | |
# - id | |
# - first_name | |
# - last_name | |
# - organization_id | |
class User < ApplicationRecord | |
has_many :preferences | |
end | |
# UserPreference has the following columns: | |
# - id | |
# - user_id | |
# - name | |
class UserPreference < ApplicationRecord | |
belongs_to :user | |
end | |
Organization.first.users.each do |u| | |
puts "#{u.name} - #{u.preference.name}" | |
end | |
# I want to see a list of users with their preferences that looks like this: | |
# Forrest Gump - Chocolates | |
# Forrest Gump - Running | |
# Dorothy Gale - Toto | |
# Dorothy Gale - Home | |
# Darth Vadar - Dark Side | |
# Would this code work? Why? | |
# How would you improve it? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment