国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Laravel wei? eloquent, wie man einer Anfrage beitritt
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-16 16:51:58
0
6
1436

Annahme

One Piecethread(帖子) 預加載 comments(評論)和 comments.user (Benutzer, der kommentiert hat)

Normalerweise k?nnen Sie es mit nur einer Codezeile erhalten

$thread = Thread::with('comments', 'comments.user')->first();

Das ist kein Problem und kann sehr gut abgefragt und angezeigt werden.

$comment = $thread->comments[0]; // Comment Model
$user = $comment->user; // User Model

Aber die aktuelle Forderung lautet: Wenn Benutzerdaten, die einen Kommentar abgegeben haben, gel?scht werden, k?nnen die natürlich zugeh?rigen Kommentardaten nicht angezeigt werden, da sonst die Informationen unvollst?ndig sind (ist das eine normale Forderung, oder?)

Dann gibt es logischerweise nur noch inner join 查詢就可以過濾掉不符合的數(shù)據(jù).
LaravelEloquent 目前我只查到withMethode

Dieser Bedarf kann leicht gel?st werden durch YiiActiveRecord

$thread = Thread::find()->innerJoinWith(['comments', 'comments.user'])->one();

Ich bin damit nicht sehr vertraut, daher m?chte ich einen Experten auf diesem Gebiet fragen, wie man es l?st. Vielen Dank!Laravel

PHP中文網(wǎng)
PHP中文網(wǎng)

認證高級PHP講師

Antworte allen(6)
習慣沉默

laravel中查詢構(gòu)建器中的join默認就是inner join的行為,手冊是這么說的

給我你的懷抱
$thread = Thread::with(['comments' => function ($query) {
    $query->whereNotNull('user');
}, 'comments.user'])->first();
巴扎黑

Eloquent ORM沒有直接的join查詢條件,但也有變通方法,如樓上所說。
不過我一般不用ORM,因為性能原因。我用Query Builder。

洪濤

\DB::('threads')
       ->where(['threads.id'=>$id])
       ->leftJoin("comments",'therads.id','=','comments.tid')
       ->paginate() 
巴扎黑

在關(guān)系里寫上join就好了,->hasMany()->join()->where() 想怎么寫怎么寫

世界只因有你

其實我問的主要是用法, 這種需求很常見. 主要是問下有沒有這方面的問題

這個在rails里都是有實現(xiàn)的
laravel 目前我看到的只有一個with

rails里有 preloadincludes、Eager load、Joins, 可以來區(qū)別eager loading數(shù)據(jù)的方式.
這里有篇文章來講解
http://www.mamicode.com/info-...

YiiActiveRecord也有with, joinWith(inner join, left join ....) innerJoinWith, 來根據(jù)需求做eager loading

其他的我就不查了. 并不是我要損laravel, 我是到現(xiàn)在也沒有覺得laravelEloquent強大在哪里

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage