I welcome back to module to databases. This is lesson to skim a design, and we are in sub lesson 2.6 polymorphic models. So what is a polymorphic model? Well, you don't have to get too scared of the term if we look at the meaning of the term, it simply means that many forms
and the way that gets applied in a lot of database applications is via e
type calm. So if we pull up the note table from the axiomatic and database and we focus on this entity type column
and we go on, look at the data
and we filter on entity type by just clicking a little filter button and dear,
we'll see all of these different types that we can filter on, and these types are different object types within the application. So let's say I want to find the employees notes. All I have to do is go to the E p employee type. I'll select that that adds the entity type constraint at the top. This is what D Beaver does for us
writing a query, though I would simply add this constraint to that query to get the employees notes.
And that pulls out all the employees notes now in similar fashion. If I wanted to get a different type, I would just add a constraint that focused on that type.
Well, there's the email account type.
And indeed, even if we get rid of this, that will turn off the filter. We'll see all the types again,
and that's it. That's the type column being used to create a polymorphic model within the database. Now, how would you solve this problem if you didn't want to use the type column? For some reason, you know you didn't know about it or you didn't want to use it Well, what you might see someone do is make a bunch of tables for each different type of note. Now that's not something you want to do, and that's
pretty apparent pretty quickly. Within the automatic a database.
We can already see that that would be somewhere along the lines off,
maybe 30 to 40 tables. I didn't count him, but it looks like it would be close to that, and that's a lot more tables than we need when we can just use one table to solve it. by just including the type within that table itself.
So that completes this lesson. We discussed the polymorphic table by using the note table for Mathematica as an example, and we were able to see that this was a polymorphic table because of the entity type column, which indicates different types of notes. I hope you enjoy this lesson and I hope to see you in the next thank you.