Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Single Table Inheritance

'Customer' and 'Employee' not inheriting from 'Account'

I made sure I followed along with Hampton and yet when I run 'Customer.first' and/or 'Employee.first' I don't get any reference to the Account table. I've included lots of my code below; please let me know if you see any obvious errors.

Here's my code from Sublime:

class RemoveOldTables < ActiveRecord::Migration
  def up
    Customer.all.each do |c|
      Account.create(name: c.name, about: c.about)
    end

    Employee.all.each do |e|
      Account.create(name: e.name, email: e.email)
    end

    drop_table :customers
    drop_table :employees
  end

  def down
  end
end
class Employee < Account
  has_many :time_entries
end
class Customer < Account
  has_many :time_entries
end
class Account < ActiveRecord::Base
end

And the output from Terminal:

2.2.1 :003 > Employee.first
  Employee Load (0.4ms)  SELECT  `employees`.* FROM `employees`  ORDER BY `employees`.`id` ASC LIMIT 1
 => #<Employee id: 1, name: "Thomas", email: "tmurray@wholesale.com", created_at: "2015-11-30 05:48:17", updated_at: "2015-11-30 05:48:17"> 
2.2.1 :004 > Customer.first
  Customer Load (0.2ms)  SELECT  `customers`.* FROM `customers`  ORDER BY `customers`.`id` ASC LIMIT 1
 => #<Customer id: 1, name: "Bob's Wholesale", about: nil, balance: nil, created_at: "2015-11-30 02:11:06", updated_at: "2015-11-30 02:11:06", email: "bob@wholesale.com"> 

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

Did you get any errors or odd messages when you did 'rake db:migrate'? Because those tables shouldn't exist anymore if it run correctly.

Thanks for the help Seth. Here's the output from my 'rake db:migrate' command. The only odd thing I notice is that there's no reference to the 'Customer' or 'Employee' models - just 'RemoveOldTables'.

biller [master] :> rake db:migrate
== 20151130193508 RemoveOldTables: migrating ==================================
== 20151130193508 RemoveOldTables: migrated (0.0000s) =========================
Tim Knight
Tim Knight
28,888 Points

And you did create the Accounts table that Hampton does at 2:00 in right?