<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 閱讀(539) 評論(0)  編輯  收藏 所屬分類: PHPSymfony


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


    網站導航:
     

    導航

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

    統計

    常用鏈接

    留言簿(7)

    隨筆分類

    隨筆檔案

    相冊

    Photo

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲综合av一区二区三区不卡| 国产乱色精品成人免费视频| 久99久精品免费视频热77| 久久精品成人免费国产片小草| 精品国产污污免费网站入口| 一本一道dvd在线观看免费视频| 看免费毛片天天看| 黄色免费在线网址| 一级中文字幕乱码免费| 国产成人无码免费看片软件| 九九热久久免费视频| 日韩精品无码免费专区网站| 一级毛片免费观看| 亚洲美女视频免费| 可以免费看黄视频的网站| 最近最新的免费中文字幕| 精品剧情v国产在免费线观看 | 丁香婷婷亚洲六月综合色| 亚洲人成小说网站色| 亚洲av无码无线在线观看| 国产成人精品亚洲| eeuss影院www天堂免费| 成全在线观看免费观看大全| 亚洲视频免费在线观看| 免费国产作爱视频网站| 国产麻豆免费观看91| 亚洲高清最新av网站| 国产精品亚洲成在人线| 亚洲色欲www综合网| 国产成人亚洲综合一区 | 亚洲熟妇中文字幕五十中出| 久久久久久亚洲精品| 中文字幕亚洲免费无线观看日本| 久久精品亚洲视频| 亚洲av日韩av综合| 成人精品国产亚洲欧洲| a级精品九九九大片免费看| 99精品视频在线视频免费观看| 男人的好看免费观看在线视频| 国产免费人视频在线观看免费| 国产a v无码专区亚洲av|