Sort elements through child objects - typo3

I have an item object with an 1:n relation to categories.
Lets say categories is a numeric value.
I tried to sort all items as per categories with setOrderings() but it doesn't work.
//inside findAll() in my ItemRepository
$query->setOrderings(array("item.categories" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
How can i get my query to sort all items according to their child objects categories?
EDIT: Example
Item1 has categories[1,2,8], Item2 has categories[1,2,5] so the ascending sort order would be: Item2, Item1

I think,
$query->setOrderings(array("item.categories" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
here 'item.categories' is an array variable that's why it is not working.
So you have to create a new element (ex: item.categorie) inside item object for each item (you sort based on the max category number, the value of 'item.categorie' should be this max category number). Now 'item.categorie' will be a normal variable with value like 5 or 8 etc...
Then,
$query->setOrderings(array("item.categorie" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
Will work...

Related

OrderBy / Sort list by secondary value in Flutter / Dart for duplicates

How do I sort a list with a secondary value - So the list is first sorted by one value then for duplicates of the first value the list is then sorted by a secondary value? Basically I need the functionality you get in SQL queries using orderby valueOne, valueTwo.
valueOne and valueTwo are both ints.
I can sort by single value using:
list.sort((a, b) => a.listValueOne.compareTo(b.ListValueOne));

Scala - how to assign entry numbers to sorted elements of a collection?

I wanted to write a method to process sales data in a way that the sales are sorted by date and concatenated with an entry number and a sale type like this:
0/2018-05-02 01:55:07/Sale type A,1/2018-09-22 02:55:07/Sale type B
But for now I could only achieve concatenating saleDate and saleType. How is it possible to produce an entry number for each record? By entry number I mean the order of sales after sorting by date
def concatSales(sales: Seq[Sale]): Seq[String] = {
sales
.sortWith(_.saleDate < _.saleDate)
.map(sale => s"$DELIMITER${sale.saleDate}$DELIMITER${sale.saleType}")
}
If you want to assign an index for each element, you can use zipWithIndex:
sales
.sortWith(_.saleDate < _.saleDate)
.zipWithIndex
.map {
case (sale, idx) => s"$idx: ..."
}
Note that you might want to use .sortBy instead of .sortWith since it looks simpler:
sales.sortBy(_.saleDate)

FileMaker calculated filtered list

I am currently getting a list of related field like so
List ( join_table::id_b;)'
and what i would like to do is filter that list by a second field in the same related table pseudo code as follows
List ( join_table::id_b;jointable:other="foo")
not really sure how to filter it down
The List() function will return a list of (non-empty) values from all related records.
To get a list filtered by a second field, you could do any one of the following:
Define a calculation field in the join table = If ( other = "foo" ; id_b ) and use this field in your List() function call instead of the id_b field;
Construct a relationship filtered by the other field;
Use the ExecuteSQL() function instead of List();
Write your own recursive custom function (requires the Advanced version to install).

how to query to a collection with array in mongodb

I Have An Array With 4 Object Items I want query to my collection and return 4 items that have this uid's...
myArray = > [{uid : 'test'},{uid : 'test2'},{uid : 'test3'},{uid : 'test4'}]
ProductCollection.find({????},(err,result)=>{})
NOTE : I dont want use any loop
I dont want use any loop
I will assume that's related to query the DB several times, one for each uid value.
Anyway, you can go to the database once to filter elements that match an array of values, like your case, using MongoDB's $in operator.
But you would have to format the uid values to an array of the values themselves instead of the array of objets, this can be accomplished with a simple .map call (don't know if you will consider this a loop) to get the filter value in the correct format.
var uids = myArray.map((item) => item.uid })
// ['test', 'test2', 'test3', 'test4']
And after that you can query your DB with this uids values
ProductCollection.find({'uid': {'$in': uids} },(err,result)=>{})
(Assuming 'uid' it the property you have in your ProductCollection that you are trying to filter by)

dynamic remove or add fields in a structure

how can I read consecutive structures from a file, when they have different fields, and create for each of them the appropriate fields (title: value)? I am a beginner. I think it is about dynamic adding new fields while reading i-th structure and dynamic removing the fields from the i-1 structure, which remained empty after reading a structure i. But how am I able to do it not knowing the names of all the fields before? For this I couldn't find example in documentation nor in the forum.
Thanks!
If some fields appear in every object, have them in a common structure that your array has instances of. For the variables fields, make a field "variable" or something in the main structure, and then dynamically assign field names and values within that structure. So for example, your structure might be:
a.name = 'Name1';
a.value = 'Value1';
a.variable.price = 50;
b.name = 'Name2';
b.value = 'Value2';
b.variable.year = 1996;
data(1) = a; data(2) = b;
where every object has fields "name" and "price" and object a has a price field but not a year field, and object b has a year field and no price field.
This will work for the kind of data you want to read in.