ClassModelList::prepareQueryHeaders()

This function can be used to simplify the SQL creation for SELECT statement.

$headers is a mixed array containing the list columns properties.

example :

name

The field name, or alias in case of foreign keys

namespace

The foreign key path, namespaced by points.


Some other headers params to know, but not used in prepareQueryHeaders() :

label

The label to show in table column.
type
The field type. Used to automaticaly instance the right renderer.



Namespacing

This following example shows how to namespace the vars through the headers.

Cook DB namespacing Foreign Keys Joomla

About the standards...

A convention is to use '_id' suffix for the foreign keys and primary keys.

example :

  • city_id (PK)
  • country_id (FK)

But this convention cannot handle the case when a table owns 2 fk pointing to the same table. In this case, you will avoid this naming convention making an exception.
Conventions are useless for automatisms if it cannot handle those exceptions.

For example, our namespacing would not work at all.

Cook allows you renaming all fields as you want but not the primary key (always id, for the moment). So you cannot adopt this standard for the moment.

Note of the conceptor : Personally, I do not like the '_id' suffixes. Maybe it can usefull in some case, but for me never because all FK fields are aliased, and it is only a matter of beiing knowing wich var represent what.
I would eventually prefer 'fk_country' for example... but even...
You can imagine the namespace : id_country.id_continent.name

Singular, plural

The namespace parts are composed of the physical field names. Not the sigularizated table alias !
As explained previously, you can use 2 fk pointing to the same table.

When a cross-reference (Xref) list is instancied in the object, it will use a plural property (highly recommended).

  • foreign key names : in singular
  • Content data fields: in singular (recommended)
  • Xref lists (N:x) : in plural

... simple and without conflicts.

The N:M tutorial is correctly written in conventions.




Field alias conventions in cook

In order to avoid conflicts, cook has defined its own conventions for building SQL joins.

example : country.continent.name

Tables aliases are singularizated. It uses the fk field name.

  • #__hellomyworld_countries =>_country_
  • #__hellomyworld_continents => _country_continent_

Fields aliases :

  • country
  • _country_name
  • _country_continent_name

In the given example, we have re-aliased '_country_continent_.name' to 'continent'.
prepareQueryHeaders() can load any data from joined tables and can provide you the alias you prefer for thos linked fields.

For loading cross-reference datas (N:M) or reversed foreign key (N:1), you can follow the tutorial.

Get Started