0

我有一个雄辩的模型,我想在一次调用中返回多个查询的结果,我希望它在一个数组中:

 public static function show_workplace($id) {
      //calculate 3 queries with queryBuilder and return their results in an array
      return [query1 , query2 ,query3] 
}

我认为返回一组查询结果会以某种方式搞砸。例如当我回来时

 return query1;

没关系 。但是当我回来

return [query1,query1]

它返回

 [{"incrementing":true,"timestamps":true,"exists":true},{"incrementing":true,"timestamps":true,"exists":true}]

这些字段不是数据库的真实字段..!

有什么想法我做错了吗?在一个函数中返回多个查询仅仅是糟糕的设计,还是我只是错过了其他东西?

4

1 回答 1

0

在查询上使用 toArray 可以解决它:

  return [Workplace::find(13)->toArray(),Workplace::find(13)->toArray()]; 

如果有人能解释这里发生了什么,那就太好了……文档对此完全含糊不清。

于 2013-10-24T20:06:03.280 回答