I was searching for an elegant way to do table joins with objects that encapsulate database tables. The TableJoin object auto-populates the foreign keys. TableJoin is allowed to make direct sql calls to do its business, but it doesn't descend from the main Database object, so I'm not sure if I want to give it that kind of power without being a Database subclass, or at least going through the Database object. Haven't decided if that's overkill or just good delegation of authority.
A quick note about the select() method: The first argument is readable, but the next arguments refer to the where clause, the order, the direction and the (unused, here) limit. ( php ) ✂
Another option could be something like the following, since the $databases will be the same, just let the TableJoin object create the Table objects within itself: ( php ) ✂
The only reason I didn't do it this way already is because the code that uses this snippet also wants to keep using the $phil object for other nefarious purposes.
Minor aside: One thing I like about languages like Objective-C are their encouraged method naming in cases like that selection method, which would make remembering what to pass in part of knowing the method name. (Such a method doesn't exist, but is what I'd have the option of using if I made this method in Obj-C.)
( objc ) ✂
works = [philAuthor select:selectionArray
where:whereClause
inOrder:wholeOrder
ascending:TRUE
withLimit:nil];
which somehow doesn't look quite as good in most languages, which don't break up the method name into multiple parts, as in this rough PHP equivalent: ( php )