문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top