我想这样做:
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();
但它如何与三个或更多表一起使用?
答案 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();