Zend Select with self join overwriting fields

前端 未结 3 1697

Posts and comments are stored in the same table. So to get each post and its comments we do this:

    $posts = $this->select()->setIntegrityCheck(false)
           


        
3条回答
  •  滥情空心
    2021-01-27 11:27

    If you alias all the columns in the second join to posts (like idPost as child_idPost... etc), you'll get many rows that are the parent row with the columns of the second row. Thats about the closest you'll get. You can then grab the parent data from the first row, and then loop through the subsequent rows to get your one-to-many data.

    Otherwise, just do two queries, one for the parent, one for the children. It may be faster than creating that large result table anyway.

提交回复
热议问题