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

David Gross
David Gross
19,443 Points

ActiveRecord Basics - TimeEntry model relationship

I am a little bit confused on the TimeEntry model. Why is there only belongs_to :employee and not also belongs_to :customer ? In my customer and employee models they both have has_many :time_entries.

 class Customer < Account
   has_many :time_entries
 end
class Employee < Account
  has_many :time_entries
end 
 class TimeEntry < AccountEntry
  belongs_to :employee 
 end

1 Answer

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

I think you're right about this. This is weird because time_entries table has customer_id column and also (as you mentioned) Customer model has has_many :time_entries in this video. There's still one-to-many relationship between account and account_entries, but it should have belongs_to :customer in TimeEntry class if we need to do something like @customer.time_entries.