<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

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产精品ⅴa在线观看| 中文字幕无码成人免费视频| 国产无遮挡吃胸膜奶免费看视频| 亚洲AV无码专区在线亚| 在线视频观看免费视频18| 国内精品久久久久影院亚洲| 好男人www免费高清视频在线| 亚洲人成电影青青在线播放| 精品久久久久成人码免费动漫| 亚洲伊人精品综合在合线| 成全视频在线观看免费高清动漫视频下载 | 亚洲一区二区三区乱码A| 本道天堂成在人线av无码免费| 亚洲无码黄色网址| 99精品视频在线观看免费| 亚洲国产高清在线| 欧美日韩国产免费一区二区三区| 亚洲欧美日韩一区二区三区在线| 免费看国产精品麻豆| xxxx日本在线播放免费不卡| 亚洲AV无码久久寂寞少妇| 九九精品免费视频| 无码日韩人妻AV一区免费l| 人人狠狠综合久久亚洲婷婷| 最近免费视频中文字幕大全| 亚洲中文字幕久久精品无码A| 免费日韩在线视频| 日韩精品无码免费专区午夜| 亚洲图片激情小说| 全黄a免费一级毛片人人爱| 成人精品一区二区三区不卡免费看| 亚洲日产2021三区在线| 国产免费黄色大片| 免费污视频在线观看| 亚洲www77777| 亚洲国产无套无码av电影| 99久久精品日本一区二区免费| 羞羞视频免费网站含羞草| 亚洲AV无码一区二区二三区入口 | 国内精品免费视频精选在线观看| 亚洲伊人久久大香线焦|