doudao9915 2013-10-29 16:03
浏览 18
已采纳

如何使用3个或更多表进行Propel查询?

I want to do this:

    SELECT * FROM `mydb`.`table1`
        INNER JOIN `mydb`.`table2`
            ON `table2`.`table1_id` = `table1`.`id`
        INNER JOIN `mydb`.`table3`
            ON `table3`.`id` = `table1`.`table3_id`
        WHERE `table2`.`myfield2`='string1'
        AND `table3`.`myfield3` = 'string2';

query on Propel, but can't find the right way to do it. With only two tables join() seems to work fine like this

$query = Table1Query::create()
            ->join('Table2')
            ->where('Table2.myfield2 = ?',  $string1)
            ->filterByMyfield3($string2)
            ->findOne(); 

But how does it work with three or more tables?

  • 写回答

1条回答 默认 最新

  • duanfan1869 2013-10-29 16:18
    关注

    Of course it is possible. You have described the mapping in a config file. Example :

    $review = ReviewQuery::create()
    ->joinWith('Review.Book')
    ->joinWith('Book.Author')
    ->joinWith('Book.Publisher')
    ->findOne();
    
    
    $book = $review->getBook()  
    $author = $book->getAuthor();      
    $publisher = $book->getPublisher(); 
    

    http://propelorm.org/documentation/04-relationships.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?