【问题标题】:Eager Loading from the model in Laravel 4从 Laravel 4 中的模型急切加载
【发布时间】:2013-03-27 05:51:02
【问题描述】:

在 Laravel 3 中,可以在模型中执行以下操作 (http://laravel.com/docs/database/eloquent#eager):

class Book extends Eloquent 
{
     public $includes = array('author');     // this line

     public function author()
     {
           return $this->belongs_to('Author');
     }
}

如果经常加载相同的模型,这很有用。

在 Laravel 4 中,添加“这一行”似乎不会导致急切加载。文档中似乎也没有提到它 (http://four.laravel.com/docs/eloquent#eager-loading)。

它是被其他东西取代还是这个功能完全消失了?


更新:

我查看了模型的源代码(很好读)。现在是:

/**
 * The relations to eager load on every query.
 *
 * @var array
 */
protected $with = array();

我有什么方法可以建议将其添加(返回)到文档中(这似乎是那些很容易被忽视的小事之一)?

【问题讨论】:

    标签: php laravel eager-loading laravel-4 laravel-3


    【解决方案1】:

    文档在 github (https://github.com/laravel/docs) 上,因此您可以提出一些要求...

    【讨论】:

    • 谢谢,我分叉了它并提交了一个拉取请求。这实际上比我想象的要容易得多:)
    猜你喜欢
    • 2014-08-13
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    相关资源
    最近更新 更多