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

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题