0

我想做这个:

    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(); 

但它如何与三个或更多表一起工作?

4

1 回答 1

2

当然这是可能的。您已经在配置文件中描述了映射。例子 :

$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

于 2013-10-29T16:18:39.300 回答