You must clone the
from AnyBlok/anyblok-book-examples repo before starting:
git clone https://github.com/AnyBlok/anyblok-book-examples -b III-06-before_polymorphisme III-06-polymorphisme cd III-06-polymorphisme
We have added some models to get started with polymorphism:
- A person blok that contains following models
Personmodel that represents people with a name and firstname
Employeemodel that adds position field on person model using polymorphism
- A university blok that represents all things regarding education
Professormodel that extends Employee model using polymorphism
Studentmodel that extends Person model using polymorphism
We also add the
University model link to the Address model, an university
could have zero or more addresses.
Polymorphism in AnyBlok allows you to get clear business readable queries as we will see later.