When designing a database, often some tables are related to others - a membership table would contain a reference to a person's id and the group id that they are a member of. Using the Link methods, you can automatically fetch objects into the parents variables.
Currently automated links are supported by column naming conventions, this feature is depreciated in favour of using the links.ini files. As this offers a more flexible and clearer way of performing these operations.
The other way of using getLink() is to use it with the second parameter which is the table name of the related table, it will then query the primary key on that table to see if it matches the value of the requested row. In this method however the getLinks() method will not work, as it will not know the related table names.
Recent versions of DB_DataObject also included support for table joins, this uses the same links.ini configuration to build join queries.
DB_DataObject Version 0.3 introduced the ability to create link ini files so you can map rows to other database columns using an ini file this ini file should have the name databasename.links.ini, and be placed in the same folder as the databasename.ini file that is created automatically by createTables.php
The Ini file contains a section for each table, then the row that is linked equal to the table and row that it should locate the row from. If you use a 'full stop' in the key (link from column), getLinks() will look up in the table with the row name matching the string to the left of the 'full stop', and replace the 'full stop' with and underscore and assign the object variable to that name.
Example 20-1. An example databasename.links.ini file
|