Timber App 
Ruby Rails Associations 
@PareidoliaX
Four Take Homes 
1. Associations are not database relationships but 
dependent on them. 
2. There is always a belongs_to side of the association. 
3. The table of the model of the belongs_to side of the 
association holds the information about the 
relationship. 
4. belongs_to works in migrations and generators.
Timber Iteration 1 
Requirements 
4 Tracks Lumberjacks and Lumberjills 
4 A Lumberjack or Lumberjill can choose on true love 
4 A Lumberjack or Lumberjill's profile shows all their 
admires
Todays Association: 
belongs_to and 
has_many
Based on the one to many 
database relationship
LumberJack Migration 
class CreateLumberjacks < ActiveRecord::Migration 
def change 
create_table :lumberjacks do |t| 
t.string :name 
t.belongs_to :lumberjill, index: true 
t.timestamps 
end 
end 
end
LumberJill Migration 
class CreateLumberjills < ActiveRecord::Migration 
def change 
create_table :lumberjills do |t| 
t.string :name 
t.belongs_to :lumberjack, index: true 
t.timestamps 
end 
end 
end
LumberJill Model 
class Lumberjill < ActiveRecord::Base 
belongs_to :lumberjack 
has_many :lumberjacks 
end
LumberJack Model 
class Lumberjack < ActiveRecord::Base 
belongs_to :lumberjill 
has_many :lumberjills 
end
Limitations of this solution 
+ Only one true love possible, can't handle complex relationships.
Four Take Homes 
1. Associations are not database relationships but 
dependent on them. 
2. There is always a belongs_to side of the association. 
3. The table of the model of the belongs_to side of the 
association holds the information about the 
relationship. 
4. belongs_to works in migrations and generators.
Find Me 
4 Twitter: @pareidoliax 
4 Website: pareidoliax.ca 
4 Github: pareidoliax 
4 email: xander.miller@gmail.com

Basic Timber App - Rails Associatios

  • 1.
    Timber App RubyRails Associations @PareidoliaX
  • 2.
    Four Take Homes 1. Associations are not database relationships but dependent on them. 2. There is always a belongs_to side of the association. 3. The table of the model of the belongs_to side of the association holds the information about the relationship. 4. belongs_to works in migrations and generators.
  • 3.
    Timber Iteration 1 Requirements 4 Tracks Lumberjacks and Lumberjills 4 A Lumberjack or Lumberjill can choose on true love 4 A Lumberjack or Lumberjill's profile shows all their admires
  • 4.
  • 5.
    Based on theone to many database relationship
  • 6.
    LumberJack Migration classCreateLumberjacks < ActiveRecord::Migration def change create_table :lumberjacks do |t| t.string :name t.belongs_to :lumberjill, index: true t.timestamps end end end
  • 7.
    LumberJill Migration classCreateLumberjills < ActiveRecord::Migration def change create_table :lumberjills do |t| t.string :name t.belongs_to :lumberjack, index: true t.timestamps end end end
  • 8.
    LumberJill Model classLumberjill < ActiveRecord::Base belongs_to :lumberjack has_many :lumberjacks end
  • 9.
    LumberJack Model classLumberjack < ActiveRecord::Base belongs_to :lumberjill has_many :lumberjills end
  • 10.
    Limitations of thissolution + Only one true love possible, can't handle complex relationships.
  • 11.
    Four Take Homes 1. Associations are not database relationships but dependent on them. 2. There is always a belongs_to side of the association. 3. The table of the model of the belongs_to side of the association holds the information about the relationship. 4. belongs_to works in migrations and generators.
  • 12.
    Find Me 4Twitter: @pareidoliax 4 Website: pareidoliax.ca 4 Github: pareidoliax 4 email: xander.miller@gmail.com