Extbase: get number of child objects - typo3

I have following model: "Shelf" and "Book", being in 1:n relation.
In the listing of shelves I need the number of books on each shelf. How can I get that?
In the database table "Shelf" there is a column "books" having the number I need. But in the model "books" is an ObjectStorage, so I cannot get the count of child object over this property.
In my list view I have
<f:for each="{shelves}" as="shelf">
...
{shelf.books.0.title} //<-- this works perfectly returning title of first book
{shelf.books.count} //<-- this produces no output

I found it myself: <f:count>{shelf.books}</f:count> is the solution

Related

How to filter with NSPredicate by an attribute of an Element I pass from the parent view?

Please help me with the following question - how do I filter a fetchRequest by an attribute of an Element I pass from the parent view?
import SwiftUI
struct aListDetailView: View {
#State var aParameter: String
#FetchRequest(sortDescriptors: [], predicate: NSPredicate(format: "elementIdentificationAttribute == %#", aParameter)) var contracts: FetchedResults<Contract>
var body: some View {
List {...}
...}
I get "Cannot use instance member 'aContract' within property initializer; property initializers run before 'self' is available".
I understand why, but how do I bypass this?
My example is a simplified version.
In truth, my query is this: I have a list of Contract elements, and each contract has a list of invoices issued in regards to that specific contract. Each contract has a unique serial code I give it, as an attribute.
My #FetchRequest for a list of all Contract elements is in Content View. I loop through them to create a list. Each row of the list is a NavigationLink to a new view, and I pass the specific contract element to the new view.
In the new view, I need to fetch a list of all the invoices specific to that contract.
However, when I add a new invoice to create a new row in the invoice sub-view list, core data does not show the new row, for a new invoice. The new row appears only when I return to the Content View and back to the invoice view, because my #FetchRequest for Contracts is in Content View.
I thought I could bypass this issue through a #FetchRequest for a list of contracts that have an attribute of my choosing (say, an attribute contractSerialNumber) equal to the attribute instance of the contract I pass to this view.
Something like:
#FetchRequest that filters all contracts in storage by the specific, unique attribute of my choosing of the contract I passed from the Parent View. Places them in a list.
ForEach contract that has that particular attribute (which will be a list of one contract) {
ForEach contract.invoiceArray { invoice in
Text(contract.invoice.invoiceIdentificationAttribute
} }
Thank you!

How to query an n:n adjacency list map in DynamoDB without using scan

I'm trying to model a cataloging system in DynamodDB. It has "Catalogs" which contains "Collections". Each "Collection" can be tagged by many "Tags".
In an RDBMS I would create a table "Catalogs" with a 1:n relationship with "Collections". "Collections" would have an n:n with "Tags" as a Collection can have multiple Tags and a Tag can belong to multiple Collections.
The queries I want to run are:
1) Get all catalogs
2) Get catalog by ID
3) Get collections by catalog ID
I read on AWS I can use the adjacency list map design (because I have the n:n with "Tags"). So here is my table structure:
PK SK name
cat-1 cat-1 Sales Catalog
cat-1 col-1 Sales First Collection
cat-1 col-2 Sales Second Collection
cat-2 cat-2 Finance Catalog
tag-1 tag-1 Recently Added Tag
col-1 tag-1 (collection, tag relationship)
The problem here is I have to use a scan which I understand to be inefficient in order to get all "Catalogs" because a query's PK has to be an '=' and not a 'Begins With'.
The only thing I can think of is creating another attribute like "GSI_PK" and add "Catalog_1" when the PK is cat-1 and the SK is cat-1, "Catalog_2" when the PK is cat-2 and SK is cat-2. I've never really see this done so I'm not sure if it's the way to go and it takes some maintenance if I ever want to change IDs.
Any ideas how I would accomplish this?
In that case, you can have the PK be the type of the object and the SK be a uuid. A record would look like this { PK: "Catalog", SK: "uuid", ...other catalog fields }. You can then do a get all catalogs by doing a query on the PK = Catalog.
To store the associations you can have a GSI on two fields sourcePK and relatedPK where you could store records that associate things. To associate an object you would create a record like e.g. { PK: "Association", SK: "uuid", sourcePK: "category-1", relatedPK: "collection-1", ... other data on the association }. To find objects associated with the "Catalog" with id 1, you would do a query on the GSI where sourcePK = catalog-1.
With this setup you need to be careful about hot keys and should make sure you never have more than 10GBs of data under the same partition key in a table or index.
Let's walk through it. I'll use GraphQL SDL to layout the design of the data model & queries but you can just apply the same concepts to DynamoDB directly.
Thinking data model first we will have something like:
type Catalog {
id: ID!
name: String
# Use a DynamoDB query on the **Collection** table
# where the **catalogId = $ctx.source.id**. Use a GSI or make catalogId the PK.
collections: [Collection]
}
type Collection {
id: ID!
name: String
# Use a DynamoDB query on the **CollectionTag** table where
# the **collectionId = $ctx.source.id**. Use a GSI or make the collectionId the PK.
tags: [CollectionTag]
}
# The "association map" idea as a GraphQL type. The underlying table has a collectionId and tagId.
# Create objects of this type to associate a collection and tag in the many to many relationship.
type CollectionTag {
# Do a GetItem on the **Collection** table where **id = $ctx.source.collectionId**
collection: Collection
# Do a GetItem on the **Tag** table where **id = $ctx.source.tagId**
tag: Tag
}
type Tag {
id: ID!
name: String
# Use a DynamoDB query on teh **CollectionTag** table where
# the **tagId = $ctx.source.id**. If collectionId is the PK then make a GSI where this tagId is the PK.
collections: [CollectionTag]
}
# Root level queries
type Query {
# GetItem to **Catalog** table where **id = $ctx.args.id**
getCatalog(id: ID!): Catalog
# Scan to **Catalog** table. As long as you don't care about ordering on a filed in particular then
# this will likely be okay at the top level. If you only want all catalogs where "arePublished = 1",
# for example then we would likely change this.
allCatalogs: [Catalog]
# Note: You don't really need a getCollectionsByCatalogId(catalogId: ID!) at the top level because you can
# use `query { getCatalog(id: "***") { collections { ... } } }` which is effectively the same thing.
# You could add another field here if having it at the top level was a requirement
getCollectionsByCatalogId(catalogId: ID!): [Collection]
}
Note: Everywhere I use [Collection] or [Catalog] etc above you should use a CollectionConnection, CatalogConnection, etc wrapper type to enable pagination.

Getting relation table like nested objects in Propel ORM

I have a query:
UserQuery::create()
->leftJoinWith('User.Employee')
->select(array('Email','Password','Status','Employee.Email','Employee.FirstName','Employee.LastName'))
->find();
How to get Employee table as nested object, not like list of columns?
I have:
[
"Email":"test#test.pl",
"Password":"test",
"Status":true,
"Employee.Id":"4",
"Employee.FirstName":"roman",
"Employee.LastName":"stonoga"
]
But I have to have:
[
"Email":"test#test.pl",
"Password":"test",
"Status":true,
"Employee": {
"Id":"4",
"FirstName":"roman",
"LastName":"stonoga"
}
]
Many thanks for any help!
This is because Propel is treating your array the same way as how your objects are structured/related. i.e. Employee as sub-entity within User, and NOT as one object.
If you want one object, then maybe a view will help.
Another view-related question
You should use a foreign key for this
$userArray = $User->toArray()
$userArray['employee'] = $User->getEmployee()->toArray()

link multiple models on same row of sap.m.table

This may be a basic question, but it's my first, so please be kind :-).
I have a sap.m.table with two models, one model with transaction data (trxModel) and another model that is used to display a sap.m.select list (reasonCodeModel). The table model is set to trxModel.
The selected value key from the dropdown needs to update a value (ReasonCodeID) in the trxModel when a value from the reason code list is selected.
I can retrieve the selected key in the change event as so
var selKey = evt.getParameter("selectedItem").getKey();
Is there a simple way to find the trxModel relevant model path from the table row Select list value I've just modified? Or is it possible to bind the ReasonCodeID from the trxModel to the ReasonCodeID field in the reasonCodeModel?
Just an extra piece of info, The current row is selected and is accessible
var selItem = dtlTable.getSelectedItem();
2nd question and I guess could be kind of related, is there a way of getting the table model path based on the selected item (highlighted row) of the table? And vice a versa?
More details on Select & Table binding.
var tabTemplate = new sap.m.ColumnListItem(
{
::
new sap.m.Select(
"idReasonCodeSelect",
{
enabled : false,
change : function(evt) {
oS4View.getController().changeReasonCodeSel(evt);
}
}
),
Bind the resource code Select to the Table
// bind the reason codes to the reason code model
sap.ui.getCore().byId("idReasonCodeSelect").setModel(
oReasonCodeModel);
sap.ui.getCore().byId("idReasonCodeSelect").bindAggregation("items", "/results",
new sap.ui.core.Item({
key : "{ReasCodeID}",
text : "{ReasCodeDesc}"
}));
Per Qualiture comment, how do I bind the Select key to the table model ReasonCodeID value?
I found an approach to tackle the first part of my question above
From the change function on the Select, I can find the path of the table model using the following.
var path = evt.getSource().getParent().getBindingContext().sPath;
2nd Update:
On the selectionChange event on the table, there's a couple of options to find the associated model path or model content.
// find the model path
oModelPath = selItem.getBindingContext().getPath();
// model values
oItem = oEvent.getParameter("listItem").getBindingContext().getObject();
So my only remaining issue, While I loop through the table model results (trxModel) and I want the Select List (using setSelectedKey) to reflect the ReasonCodeID value in the trxModel.

How can I create a link in orientdb studio?

In this link there is a very basic example.
I have a class, its name is "dog" and it has a "name" property and a "childs" property. The "childs" property type is LINKLIST.
When a try to create a new dog object I crete a "childs" field but I don't know how to fill it.
Please point me to a more complete tutorial (actualy I search it with out success).
You can use the query for that:
insert into animal set name = 'dog', children = [<rid>]
where <rid> is the record id of the child.