Load Methods that Utilize Database Indexes

As you saw in the previous example, the Code Generator will always generate two load methods, load() and loadAll(), for every code generated class. load() takes in the primary key (or primary keys if you have multiple PKs defined on the table) as the parameter, while loadAll() simply returns all the rows in the table.

Using database indexes, the code generator will also generate additional load-type methods given the way you have defined those indexes. In our Examples Site Database, there are quite a few indexes defined, but we will highlight two:

Given these two indexes, the code generator has generated loadArrayByLastName() in the Person object, and it has defined loadByUsername() in the Login object.

The LastName load method returns an array while the Username load method returns just a single object. The code generator has recognized the UNIQUE property on the column, and it generated code accordingly.

You could also define indexes on multiple columns and the code generator will generate load methods based on those multi-column keys.

Using loadByUsername() to get a single Login object

Login ID: 1
Login Username: jdoe
Login Password: p@$$.w0rd

Using loadArrayByLastName() to get an array of Person objects

Using countByLastName() to get a count of all "Smiths" in the database

There are 3 person(s) who have a last name of "Smith" in the system.