作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在考虑使用 Laravel 开发一个新站点。我正在阅读关于 http://vegibit.com/laravel-eloquent-orm-tutorial/ 的教程,关于使用 Eloquent 连接表和检索数据。在最后一个示例中,他们实际上是在尝试进行连接,但 Eloquent 仍然在执行两个查询而不是一个查询。 Eloquent 是效率低下还是这只是一个糟糕的例子?似乎这可以简单地通过单个左连接查询来完成。任何人都可以对此提供一些见解吗?有没有更好的方法来执行这个查询?具体例子是:
Route::get('/', function()
{
$paintings = Painting::with('painter')->get();
foreach($paintings as $painting){
echo $painting->painter->username;
echo ' painted the ';
echo $painting->title;
echo '<br>';
}
});
以下查询的结果:
string ‘select * from paintings‘ (length=25)
string ‘select * from painters where painters.id in (?, ?, ?)’ (length=59)
Leonardo Da Vinci painted the Mona Lisa
Leonardo Da Vinci painted the Last Supper
Vincent Van Gogh painted the The Starry Night
Vincent Van Gogh painted the The Potato Eaters
Rembrandt painted the The Night Watch
Rembrandt painted the The Storm on the Sea of Galilee
最佳答案
Eloquent 对于快速构建某些东西非常有用,并且还具有查询缓存,它非常易于使用,但是对于需要随时间扩展的大型项目来说,它可能不是理想的选择,我的方法是使用带有契约(Contract)的存储库模式仍然可以使用 Eloquent 的强大功能,并拥有一个允许我在需要时轻松更改实现的系统。
关于php - Laravel Eloquent - 效率低下吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30606382/
我是一名优秀的程序员,十分优秀!