1
Constructing Collections
2
========================
4
Collections can be retrieved in many ways, including:
6
* From a related object
7
* Through manual instantiation.
13
$author = Author::constructByKey($authorId);
14
$books = $author->getBook_Collection();
16
Through manual instantiation
17
----------------------------
19
$book = new Book_Collection();
25
$book = new Book_Collection();
26
$book->loadBySql($sql);
28
Building on the base SQL
29
------------------------
31
Building on the base SQL is currently somewhat of a challenge, as it requires knowledge of what parts of the SQL the base includes. As such, it might be necessary to use PHP's string functions to replace parts of the SQL.
33
Assuming the base SQL doesn't include an ORDER BY clause, the following would work:
35
$book = new Book_Collection();
36
$sql = $book->getLoadSql();
37
$sql .= ' ORDER BY book.title DESC LIMIT 100';
38
$book->loadBySql($sql);
40
In the future, it could work like this:
42
$book = new Book_Collection();
43
$sql = $book->getLoadSql();
44
$sql->setOrderBy('book.title DESC');
46
$book->loadBySql($sql);