Get Objectdata including m:n data

Happy new year!

Starting with a general question: Is there a kind of function to get the data of an object (selectData(id)) including the m:n fields?

Currently I’m doing a selectData() and then the necessary SelectManyToManyData() of the fields I need. A function like getObjectData() would be helpful.

There was something like that in Mura which was really slow, and I know there are some cavats getting data (which fields of the m:n data, etc.).

Best Michi

What would the result look like and what are some example use cases? It feels like this has been asked before.

The use case is pretty simple: Events with categories

I want to output a list of the next 5 events and show the categories.

What I normally do here is getting the events in a handler, loop over the result and get the categories of each record and build my own array of structs and the loop over the array in my view.

A possibiliity to get the categories within a select would be cool.

The result could be like this:

[
  { eventID,
    eventTitle,
    start,
    ...,
    categories : {
                   id,
                   label,
                   colour
                 }
  },
  { eventID,
    eventTitle,
    start,
    ...,
    categories : {
                   id,
                   label,
                   colour
                 }
  },
  .
  .
  .
]

the selectData could look like this:

return all m:n fields of categories

obj.selectData(
  selectfields = ["eventID", "eventTitle", "start", "categories"],...)

or with only some fields of categories:

obj.selectData(
  selectfields = ["eventID", "eventTitle", "start", "categories(id,label,colour)"],...)

performance wise I think it’s not a big difference if I do the selects by my self or selectData can do this. But it could save much code if I can do this with a systemfunction already.

What do you think?

selectData can already do this, but a little more verbose:

selectData( ..., selectFields=[ "categories.id as categoryid", "categories.label as category", ... ] )

Does this achieve what you’re after? - or you want the a result set that has this subquery as just a field on the main query?

Sorry, yes I see. So really a syntax to help you more easily achieve this. Like:

selectData( selectFields=[ 
    "id"
  , "label"
  , "expand:categories( id,label,something )"
  , "expand:tags" 
] )

Or similar. Perhaps some kind of special formula field like we have with the agg:

property name="categories_expanded" formula="expand:categories( id,label )";
1 Like

I like this syntax. Could help a lot and the selectData can still be used. Perfectly backwards compatible.

https://presidecms.atlassian.net/browse/PRESIDECMS-2992

1 Like