簡體   English   中英

Typo3 Extbase:如何按子對象的屬性對父對象進行排序

[英]Typo3 Extbase: How to sort parent objects by property of child objects

假設我有一個 extbase 擴展,其父對象“foo”與子對象“bar”有 m:n 關系。 每個“bar”對象都有一個整數屬性“barNum”。 我想對我的“foo”對象進行排序,其中一個包含具有最低“barNum”值的“bar”對象。 我怎樣才能做到這一點?

我可以按 foo 對象的字段進行排序,例如:

class FooRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
    protected $defaultOrderings = [
        'fooField' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
    ];
    }

但是我看不到任何按 m:n 相關子對象的字段排序的方法


澄清:例如,如果我的數據如下所示:

"foos": {
    "foo1": {
        "bars": {
            "bar1": {
                "barNum": 31
            },
            "bar2": {
                "barNum": 42
            }
        }
    },
    "foo2": {
        "bars": {
            "bar3": {
                "barNum": 82
            },
            "bar4": {
                "barNum": 19
            }
        }
    },
    "foo3": {
        "bars": {
            "bar5": {
                "barNum": 37
            }
        }
    }
}

我希望它按foo2, foo1, foo3排序,因為 19 < 31 < 37。

您可以使用. ,例如fooFieldWithObject.barField

在你的情況下,我會嘗試: bars.barNum

class FooRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
    protected $defaultOrderings = [
        'bars.barNum' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
    ];
}

暫無
暫無

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

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