Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.