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

时间:2013-10-29 16:03:16

标签: php mysql sql codeigniter propel

我想这样做:

    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';

在Propel上查询,但无法找到正确的方法。只有两个表join()似乎工作得很好

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

但它如何与三个或更多表一起使用?

1 个答案:

答案 0 :(得分:2)

当然有可能。您已在配置文件中描述了映射。 示例:

$review = ReviewQuery::create()
->joinWith('Review.Book')
->joinWith('Book.Author')
->joinWith('Book.Publisher')
->findOne();


$book = $review->getBook()  
$author = $book->getAuthor();      
$publisher = $book->getPublisher(); 

$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