3.1. Introduction

The SQL-oriented ORM (model) system in Solar is relatively full-featured and powerful. For good or bad, this means there is some necessary complexity to go along with it.

[Note] Note

You don't have to use the model system, but it is very strongly recommended even in simple cases. The Solar model system gives you a lot of reward for relatively little effort, and gives you room to grow even when not using all of its features.

If you feel the need to avoid it, for whatever reason, you can fall back to using the Solar_Sql_Select class (a QueryObject implementation), or even to the lower-level Solar_Sql_Adapter system based on PDO. The model system itself uses those classes for its foundations.

In this chapter, we will go over:

  • the components of the model system and the design patterns to which they correspond;

  • how to retrieve a model object from the model catalog;

  • how to fetch a record or collection from the database based on arbitrary criteria;

  • how to read through the results of a fetch using records and collections;

  • how to create, load, modify, and save a record;

  • how to add filters to sanitize and validate record data;

  • the various "special" column behaviors available to models; and

  • single-table inheritance.