akeeba/fof — pull request #261 by nikosdion (2014-01-16 18:23:12+00:00)
Title: Close gh-258 ORM-like interface in FOFTable

**FOFDatabaseIterator**
Allows you to iterate through a database result set using a forward-only iterator which returns FOFTable objects.

**FOFModel::getIterator()**
Works like getItems() but returns a FOFDatabaseIterator instead of list of dumb stdClass objects. It is great for iterating through very large lists of records without having to load everything in memory.

**FOFTable::getRelations()**
Returns a FOFTableRelations object which is used to manage relations. The relations can be configured in PHP code or via fof.xml (documentation: to-do). The possible relations you have are:
* Parent (1:∞ relation). Your table belongs to another table. For example, a comment belongs to an article.
* Siblings (1:∞ relation). All items in the same table with the same parent. For example, all comments belonging to the same article as the current comment. It's an extension of the parent relation and can't be assigned on its own.
* Child (a.k.a. 1:1 relation, or "only child"). One to one relation with another table, usually used to extend a foreign table's fields without touching its schema
* Children (the opposite side of the "parent" 1:∞ relation). All items having our table as the parent. For example, all comments belonging to this article.
* Multiple (∞:∞ relation). This relation uses a pivot (a.k.a. map or glue) table. Think users to user groups to get the picture. It is used to return the foreign table's items which are related to us, for example all user groups this user is assigned to.

So far the relations are read only, i.e. you can use them to fetch FOFTable objects (or FOFDatabaseIterator objects which in turn return FOFTable objects). You can then manipulate the FOFTable objects as you please. The only downside is the Multiple (∞:∞) relation; there is currently no provision for automatically handling the glue table in FOF. However, with the work already done on the relations in this PR something like that can *finally* be implemented. I'll leave it for another day.