簡體   English   中英

基於其他表的TYPO3 Extbase查詢

[英]TYPO3 Extbase query based on other table

我到桌子上一個與另一個有關

TABLE A
uid
name

TABLE B
uid
name
rel_table_a

現在我想:

// find all table A that is related to by table B
public function findAllTableAThatIsRelatedToByTableB() {
  $query = $this->createQuery();

  // what should this line be?
  //$query->matching($query->count(tableB.rel_table_a = uid));

    return $query->execute();
}

是否可能,或者首先需要在TCA中為表A創建關系。

您可以在查詢中使用相關表,但首先需要正確設置TCA和模型,否則extbase不知道表之間的關系。

作為查詢條件,您只需檢查該關系是否存在。

在您的結構中,由於表A沒有關系字段,因此我們只能在表B上執行此查詢,因此在此示例中,您將從表B中獲得與表A元素相關的所有項目。

$query->matching($query->greaterThan('rel_table_a.uid', 0));

如果從表A到表B具有1:n關系,則應使用內聯字段。 這樣,您可以在表A上進行查詢: https : //docs.typo3.org/typo3cms/TCAReference/Reference/Reference/Columns/Inline/Index.html

PS:您不能在$query->matching內使用$query->count

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM