[英]Typo3 Extbase: How to sort parent objects by property of child objects
Say I have an extbase extension with parent objects "foo" with an m:n relationship to child objects "bar".假设我有一个 extbase 扩展,其父对象“foo”与子对象“bar”有 m:n 关系。 Each "bar" object has an integer property "barNum".每个“bar”对象都有一个整数属性“barNum”。 I want to sort my "foo" objects by which one contains a "bar" object with the lowest "barNum" value.我想对我的“foo”对象进行排序,其中一个包含具有最低“barNum”值的“bar”对象。 How can I do this?我怎样才能做到这一点?
I can sort by fields of the foo object like:我可以按 foo 对象的字段进行排序,例如:
class FooRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
protected $defaultOrderings = [
'fooField' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
];
}
But I don't see any way to sort by a field of an m:n related child object但是我看不到任何按 m:n 相关子对象的字段排序的方法
To clarify: for example, if my data looks like this:澄清:例如,如果我的数据如下所示:
"foos": {
"foo1": {
"bars": {
"bar1": {
"barNum": 31
},
"bar2": {
"barNum": 42
}
}
},
"foo2": {
"bars": {
"bar3": {
"barNum": 82
},
"bar4": {
"barNum": 19
}
}
},
"foo3": {
"bars": {
"bar5": {
"barNum": 37
}
}
}
}
I would want it sorted foo2, foo1, foo3 , because 19 < 31 < 37.我希望它按foo2, foo1, foo3排序,因为 19 < 31 < 37。
You can sort by sub objects and properties by using the .
您可以使用.
, eg fooFieldWithObject.barField
. ,例如fooFieldWithObject.barField
。
In your case I'd try: bars.barNum
在你的情况下,我会尝试: 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.