66日目?:symfonyが賢すぎてハマった件
現在ユーザー登録回りを作っています。
sf_guard_userと sf_guard_user_profileの2つのテーブルをどうやって joinするのかというと、listアクションのような一覧表示の場合、
public function executeList()
{
$this->sf_guard_user_profiles = sfGuardUserProfilePeer::doSelectJoinAll(new Criteria());
}
と doSelectJoinAllを使うわけです。
showアクションのような1個だけ表示する場合はどうするのかなーと思って調べ始めたのが運のつき。いくら探しても情報が出てきません。joinしない場合は、
public function executeShow() { $this->sf_guard_user_profile = sfGuardUserProfilePeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($this->sf_guard_user_profile); }
という感じ(symfony propel-generate-crudで作った場合)になるのですが、いったいどうやるんだろうとしばらく悩みました。
例えば、こんなコードを書いたり。
$this->sf_guard_user = sfGuardUserPeer::retrieveByPk( $this->sf_guard_user_profile->getUserId($this->getRequestParameter('id')));
いやー困ったなーと思った時に、ふと入力ミスをして、思わず発見したのですが、joinした先のテーブルを1つ取ってくるのは何もしなくて良かったんですね。なんかデフォルトで自動で取ってきてくれるみたいです。あーら、そうだったのね。
という訳で、
public function executeShow() { $this->sf_guard_user_profile = sfGuardUserProfilePeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($this->sf_guard_user_profile); }
これでOK。
symfonyはお利口さんです。ほんと。
だけど、joinしてるテーブルがすごく重い場合とかはどうするんだろう? まぁいいか。