Laravel 多对多 - 意外的结果集 ->select()
问题描述
我想知道是否有人可以提供帮助,因为我遇到了困难并且仍在学习 Laravel ORM.任何人都可以解释为什么,当我运行时:
I wonder if anyone can help, as I've hit a wall and still learning Laravel ORM. Can anyone explain why, when I run:
我得到了这个结果集:(剪断了...)
I get this result set: (snipped...)
这是王牌!但是,当我开始从 location_tags 连接中选择我想要的列时,使用:
Which is ace! However, when I start to select the columns I want from the location_tags join, with:
我最终得到:
谁能解释一下这是怎么回事?并可能指出我正确的方向来限制选择?谢谢!
Can someone explain what's going on? And possibly point me in the right direction to limit the selects? Thanks!
更新我也试过:
返回相同的结果:(
推荐答案
想通了.这里的关键是你必须包含至少一个 Laravel 可以用来映射结果集的键的 select()
值.就我而言,它是 user_id
,如下所示:
Figured it out. The key here was that you must include a select()
value of at least one key that Laravel can use to map the result set. In my case it was user_id
, like so:
然后返回一个更好的结果集:
Which then returns a much nicer results set:
希望这对未来的人有所帮助,因为它让我猜了好几个小时.
Hope this helps someone out in the future, because it kept me guessing for a good couple of hours.
这篇关于Laravel 多对多 - 意外的结果集 ->select()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!