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

Peter Lawless
Peter Lawless
24,404 Points

How does Rails know to filter on :type with this single table inheritance example?

So while watching this video I see that we set the type on our two objects in the database to "Customer" and "Employee" respectively, and when we query the database via the console for the first Customer, it returns its queryset by using a clause like "WHERE accounts.type IN ('Customer')" as a filter. But when we set the type in the console, we could have written in any string at all, even something like:

a = Account.first
a.type = "Puppy"
a.save

What I'm getting at is this: How can Rails attach meaning to some string fields, but not necessarily others like the :about or :name field on our Account model? If we give our accounts a bogus types, what happens then?