Is it possible to have an eloquent query builder return StdClass
rather then Model
?
例如,User::where('age', '>', 34)->get()
返回User
个型号中的Collection
个.
而DB::table('users')->where('age', '>', 34)->get()
返回StdClass
个对象的Collection
.快多了.
因此:
Is it possible to prevent hydrating eloquent models and return StdClass
objects as a database query builder would, but still leverage the usefulness of an eloquent query builder syntax?
我不明白为什么这个问题被否决了.它的期望和措辞相当清楚.人们应该将鼠标悬停在向下投票的图标上,并看到"这个问题没有显示任何研究成果;它不清楚,也没有帮助"的提示.
Laravel社区有一种强烈的信念,即如果你站在Eloquent 之外,你就是在过早地优化.这是不正确的,在有10000多行从数据库结果中提取有说服力的模型的情况下,速度非常慢.我们谈论的是几秒钟,有时是几十秒钟和沉重的记忆.
Laravelers would then state "Just do a DB::query()
its faster". Yes.. Yes... it is im aware... Although I'm asking in this very question... right here... above.. clearly worded and concise... Can I use Eloquent Query Builder to build the query and have StdClass objects returned so as to not hydrate thousands of Eloquent models with all the overhead. Already I hear the Laravelers "Why not use DB::query()
then?" Because I'm NOT asking that... Im asking can we use the Eloquent syntax its easier and more readable than doing joins....
我不是在这里询问有关应用程序架构的建议.我们希望这样做有很多深层次的原因,比如匹配ElasticSearch存储库的输出等等...但我不必进入"为什么"——这是一个问答论坛.不是讨论或建议平台.
- Face palm