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

Travis Eubanks
Travis Eubanks
12,566 Points

log_time(amount, customer)? Not making sense.

Im confused on how the method log_time(amount, customer) is working.

Why is when you call that method on an Employee object the account: is set to customer?

Wouldnt you set it to (self) because you want it to save to an entry by an employee?

Samuel Johnson
Samuel Johnson
9,152 Points

I havent seen the code but guessing this is something to do with single table inheritance? The idea is that the account table will store employees and customers? This is just my first guess..

1 Answer

Travis Eubanks
Travis Eubanks
12,566 Points

Yes this is a STI question. Yes, the Account table stores Customer and Employees (Customer model and Employee model inherit from Account table). I guess im just confused on why they would set an account from a passed argument when calling self on the account: attribute should suffice.

class Employee < Account has_many :time_entries

def total_hours time_entries.sum(:time) end

def log_time(amount, customer) TimeEntry.create(time: amount, employee: self, account: customer) end end

Heres the snippet of code if this helps render my question

Thanks in advance!