+1 571-297-6383 | info@sonjara.com

Enhanced Database Joins

This week's new feature is way down at the framework level. The InnerJoin class has been around for years, but until now there was no support for other database joins. Well now there is.

The InnerJoin class has been refactored into an abstract base class AbstractJoin and
a concrete implementation class, which keeps the name InnerJoin. You still use it the same way as before:

$join = new InnerJoin();
$join->add(Employee);
$join->add(Office);
$results = $join->query("WHERE salary < 40000");

This would return an inner join across the two tables, meaning that employees that were not assigned to an office would not be returned in the result set. The only difference (behind the scenes) is that the result objects being returned are now of class JoinResult rather than InnerJoinResult as was previously the case. This is just a renaming to more correctly describe the class, since there is now more than one type of join.

So, how would we get a result returning the Employees not assigned to an Office? Simple:

$join = new LeftOuterJoin();
$join->add(Employee);
$join->add(Office);
$results = $join->query("WHERE salary < 40000");

For employees with no related office an empty Office object is included in the returned JoinResult. And the nicest thing about this is that because InnerJoin and LeftOuterJoin both share the same base class, they can be used interchangeably. For instance, the custom reporting module in Fakoli now has an option "Include Incomplete Matches in Results" which swaps the search mode. The implementation of this is nice and easy:

$mode = $_GET["join_mode"]);
$joinClass = ($mode == "outer") ? LeftOuterJoin : InnerJoin;
$join = new $joinClass();
$join->add(Employee);
$join->add(Office);
$results = $join->query("WHERE salary < 40000");

How about other database joins?" I hear all you database theorists cry. Well, in practical terms if you have Inner and Left Outer Joins, you have the most common use cases covered. Right Outer Joins are just Left Outer Joins backwards, so you can almost always rewrite them as such. Cross Joins (Cartesian Joins) are mostly useful as set-theoretic constructs used within a database view - NEVER use them in application logic. Full Outer Joins might be useful, but for now we will follow the Fakoli mantra of not building things until you need them.

If you need a quick reference to the specifics of different joins, look here:

http://en.wikipedia.org/wiki/Join_%28SQL%29



A couple of format() improvements » « Component upgrade dependency resolution
 

Comments

  • クレイサス バッグ
    Posted by wardortHAto at 2013-12-16 15:56:49
    I've truly experienced delivers to complete secret merchants at banking institutions, shuttle bus gas stations, house sales/model showrooms, hotels, ケイトスペード バッグ ケイトスペード アウトレット ケイトスペード 財布 新作 2013,サマンサタバサ 財布 サマンサタバサ 財布 新作 2013 サマンサタバサ バッグ アウトレット,コーチ バッグ アウトレット コーチ アウトレット coach バッグ 斜めがけ,アナスイ 人気 アナスイ バッグ 2013 アナスイ 財布 新作,リモワ アウトレット リモワ サルサ リモワ アウトレット,クレイサス 財布 CLATHAS ポーチ CLATHAS ポーチ,グレゴリー バッグ グレゴリー バッグ グレゴリー バッグ,pubs along with locations. Once i had been try really hard to mystery store shopping, I had formed considerably more provides as compared to time frame. And so i chose to restrict the secret buying encounters to help meals for two (with the husband) which is why I would possibly be repaid. $30 as well as fifty dollars servings will be not snicker from!ケイトスペード バッグ 新作 2013 ケイトスペード アウトレット ケイトスペード アウトレット,サマンサタバサ バッグ アウトレット サマンサタバサ バッグ 新作 サマンサタバサ バッグ アウトレット,COACH 財布 新作 2013 COACH 財布 新作 2013 コーチ 財布 レディース,アナスイ 人気 アナスイミニ アナスイミニ,リモワ サルサ リモワ アウトレット リモワスーツケース,クレイサス ポーチ クレイサス 財布 CLATHAS 財布,グレゴリー ショルダー グレゴリー リュック グレゴリー ショルダー,In addition to simple fact I have only prepared some sort of secret purchase a fresh steakhouse in town. They're going to compensate me $35 for lunch for two. ケイトスペード バッグ 新作 2013 http://www.hobbyoasisinc.com/ ケイトスペード バッグ 新作,サマンサタバサ 財布 http://www.cvdinc.com/ サマンサタバサ バッグ 新作,coach バッグ 斜めがけ http://www.everybodywantsacoach.com/ coach バッグ 斜めがけ,アナスイ 人気 http://www.tysonc.net/ アナスイ 財布 新作,リモワ サルサ http://www.welcometomyworlds.com/ リモワ トパーズ,クレイサス バッグ http://www.healtharticlesworld.com/ CLATHAS 財布,グレゴリー リュック 新作 http://www.littleguybigbucks.com/ グレゴリー リュック,Might be it certainly can't include the full invoice (the technique most of us eat) yet look for a new coupon that will pay that much for supper out there at a great dine-in diner. Likewise, as a thriller customer it is best to just take projects that you like, essentially people in your city in which suit easily within your own operating schedule.
* indicates required field