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

Assoziationsobjekt - laravel\lumen Wie soll mit der bedingten Assoziation umgegangen werden?
給我你的懷抱
給我你的懷抱 2017-05-16 16:51:56
0
3
652

Ich habe derzeit 3 ??Tische,tags、product、album.

productalbum相關(guān)聯(lián)的標簽都在tags里面。通過biz_type進行區(qū)分,1表示product, 2表示album.

Die Tabellenbeziehung ist wie folgt

table_tags
    id: int
    biz_type: int 
    biz_id: int

table_product
    id: int

table_album
    id: int

Ich hoffe jetzt, die polymorphe Assoziation von tags的分頁列表,去關(guān)聯(lián)獲取productalbum的信息。
目前查看了laravel abzufragen, aber es scheint, dass dieser Ansatz nicht unterstützt wird. Gibt es eine M?glichkeit, durch Bedingungen eine Beziehung herzustellen?

給我你的懷抱
給我你的懷抱

Antworte allen(3)
洪濤

Laravel的多態(tài)的多對多關(guān)聯(lián)有講到這個,這個使用場景跟你有點類似你可以看看
http://www.kancloud.cn/baidu/...

Polymorphic Many To Many Relation Table Structure 多態(tài)的多對多關(guān)聯(lián)數(shù)據(jù)庫表結(jié)構(gòu)

除了一般的多態(tài)關(guān)聯(lián),也可以使用多對多的多態(tài)關(guān)聯(lián)。例如,Blog 的 Post 和 Video 模型可以共用多態(tài)的 Tag 關(guān)聯(lián)模型。首先,來看看數(shù)據(jù)庫表結(jié)構(gòu):

posts

id - integer
name - string

videos

id - integer
name - string

tags

id - integer
name - string

taggables

tag_id - integer
taggable_id - integer
taggable_type - string

現(xiàn)在,我們準備好設(shè)定模型關(guān)聯(lián)了。 Post 和 Video 模型都可以經(jīng)由 tags 方法建立 morphToMany 關(guān)聯(lián):

class Post extends Model {

public function tags()
{
    return $this->morphToMany('App\Tag', 'taggable');
}

}
在 Tag 模型里針對每一種關(guān)聯(lián)建立一個方法:

class Tag extends Model {

public function posts()
{
    return $this->morphedByMany('App\Post', 'taggable');
}
public function videos()
{
    return $this->morphedByMany('App\Video', 'taggable');
}

}

某草草

join?但不建議用。

劉奇

自己實現(xiàn)一個關(guān)聯(lián)查詢也可以啊,目前多態(tài)關(guān)聯(lián)的條件查詢因為過于復(fù)雜,框架并未提供。

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