Collection of scalar (int, string, ...) in Entity

I have a basic Entity on which I want to store multiple values for a String, ie:

  • A list of emails,
  • A list of tokens from a TokenList

But it does not seem possible in CUBA.

How would be the “cuba like” approach for such a scenario? ie: How would one persist a TokenList in CUBA without creating a separate Entity.

The data to store is so simple it feels overkill to create a full blown Entity for it.

Eh, overkill? Maybe. But given how quickly you can create a new entity class in Studio… does it matter? It’s gonna take you under 5 minutes to create the new entity class and define a collection of same in your main entity. And later when you need to add attributes to the “single string only” entity…you’ll be glad you started that way.

2 Likes

I found an old entry that suggests to use a Custom DataType for such simple scenarios:

Is this still the best approach? That post, and the one linked from there links to issue PL-8107 but the link is broken.

Well that issue was nearly 4 years ago.

I think an entity is going to be a lot simpler than writing custom parsing code as suggested up there. Seriously, under 5 minutes and you’re done, all automatic. And when you have to add attributes (and you will) it’ll be easier since you already have an entity class for it.

That could make kind of sense for the Email addresses example. But for a TokenList? That is and always will be a List no matter what and in does, conceptually, make sense to be held inside the Entity itself.

I’ll try both approaches anyway :wink: