<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Tao

    Tao obeys its own inherent Nature

    How To: Using symfony to add a join between tables

    1. simple join two tables

    purpose:
    generate sql like:   

    select * from photo p
        left join artist a on p.artist_id = a.artist_id
          where a.genre = 'something' and p.genre = 'something'
    

    code:           

    if(!CriteriaUtil::hasJoin($criteria, ArtistPeer::TABLE_NAME)){
        $criteria->addJoin(PhotoPeer::ARTIST_ID, ArtistPeer::ARTIST_ID, Criteria::LEFT_JOIN);
    }
    $criteria->add(ArtistPeer::GENRE, $genre);    
    $criteria->add(PhotoPeer::GENRE, $genre);

    2. join two tables, add AND OR between conditions
    purpose:
    generate sql like:    

    select * from photo p
        left join artist a on p.artist_id = a.artist_id
          where (a.genre = 'some' or p.genre='something')
            and a.name = 'something'

    code:   

    if(!CriteriaUtil::hasJoin($criteria, ArtistPeer::TABLE_NAME)){
       $criteria->addJoin(PhotoPeer::ARTIST_ID, ArtistPeer::ARTIST_ID, Criteria::LEFT_JOIN);
    }
    $criteria->add(ArtistPeer::GENRE, $genre);
    $c = $criteria->getCriterion(ArtistPeer::GENRE);
    if($c != null){
       $c->addOr($criteria->getNewCriterion(PhotoPeer::GENRE, $genre));
    }
    $criteria->add(ArtistPeer::NAME, $name);

     

    Note:
    It's a good habit to check if we have joined the table already. to check this, you can use the following util class, it get all the joined tables, and check if the table exists in them.

    class CriteriaUtil{
        public static function hasJoin($c, $table_name){
            $joins = $c->getJoins();
            if($joins != null){
                foreach($joins as $join){
                    if($join->getRightTableName() == $table_name){
                        return true;
                    }
                    if($join->getLeftTableName() == $table_name){
                        return true;
                    }
                }
            }
            return false;
        }
    }
    

    posted on 2007-12-05 17:26 wade 閱讀(533) 評論(0)  編輯  收藏 所屬分類: PHPSymfony


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    <2007年12月>
    2526272829301
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    統計

    常用鏈接

    留言簿(7)

    隨筆分類

    隨筆檔案

    相冊

    Photo

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一级毛片免费观看不卡的| 国产免费人成视频尤勿视频| 91精品国产免费| 亚洲熟妇av一区二区三区| 99精品视频在线观看免费| 亚洲午夜日韩高清一区 | 亚洲av永久无码精品表情包 | 免费无码又爽又刺激网站直播| 精品国产人成亚洲区| 一个人看的www视频免费在线观看 一个人看的免费观看日本视频www | 精品无码国产污污污免费| 亚洲va久久久久| 日韩高清在线免费看| 亚洲国产夜色在线观看| 拨牐拨牐x8免费| 羞羞视频免费网站入口| 亚洲国产一成久久精品国产成人综合| 一个人看的www免费高清| 亚洲av无码国产精品夜色午夜| 免费A级毛片无码视频| 亚洲av无码一区二区三区天堂古代| 日本妇人成熟免费中文字幕 | 亚洲成色www久久网站夜月| 精品视频在线免费观看| 亚洲福利秒拍一区二区| 成人性生免费视频| 五级黄18以上免费看| 水蜜桃亚洲一二三四在线| 欧美三级在线电影免费| 羞羞网站在线免费观看| 亚洲图片在线观看| 成人免费视频观看无遮挡| 一个人看的www在线免费视频| 91亚洲导航深夜福利| 国产成人免费高清在线观看| 中出五十路免费视频| 亚洲一本之道高清乱码| 亚洲日本中文字幕一区二区三区 | 亚洲日韩小电影在线观看| 114级毛片免费观看| 国产精品亚洲综合天堂夜夜|