Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Managed associations with XSDS

Hello all,

i'm sure i've done this before, but i just can't get the key...

I've got this CDS file with these two entities, defined as follows:

@Catalog.tableType: #COLUMN

Entity "group" {

key id: Integer64 not null;

name: Association to model.translation not null;

description: Association to model.translation;

parent: Integer64 null;

editable: Integer not null default 1;

status: Integer not null default 0;

user_id: Association to model.user;

key version: Integer not null default 1;

date: UTCTimestamp not null;

};

@Catalog.tableType: #COLUMN

Entity translation {

key id: Integer64 not null;

en: String(5000);

fr: String(5000);

de: String(5000);

it: String(5000);

es: String(5000);

zh: String(5000);

ko: String(5000);

ru: String(5000);

jv: String(5000);

ar: String(5000);

pt: String(5000);

ja: String(5000);

};

When i see the schema generated with my hdbdd file, i get this:

BIGINT


1

id

FIXED

(X1)

X

To select row, press SPACEBAR

2

name.id

BIGINT

FIXED

X

To select row, press SPACEBAR

3

description.id

BIGINT

FIXED

To select row, press SPACEBAR

4

parent

BIGINT

FIXED

To select row, press SPACEBAR

5

editable

INTEGER

INT

X

1

To select row, press SPACEBAR

6

status

INTEGER

INT

X

0

To select row, press SPACEBAR

7

user_id.id

BIGINT

FIXED

To select row, press SPACEBAR

8

version

INTEGER

INT

(X2)

X

1

To select row, press SPACEBAR

9

date

TIMESTAMP

LONGDATE

X

So I want to show the name of the group:

        var lang = "en";

        var MyEntity = XSDS.$importEntity("package", "model.group");

       

        // retrieve entity instance

   

        var query = MyEntity.$query();

       

        var results = query.$execute();

   

       

        $.response.setBody(JSON.stringify(results[0].name[lang].toString()));

But get this error:

results[0].name[lang] is undefined


i also tried results[0].name.id[lang], and many other things...

i must be missing something here, but i'm getting nuts...

many thanks in advance!

Luis

Tags:
Former Member
replied

Hello Luis,

although I do not really understand why you set up your data model as described following can help you.

Instead of var query = ... and var results = ... do following:

var results = $query().$project({name: true}).$execute();

Then you can access the value like you do it (although no JSON stringify and .toString is necessary cause the values in your language columns are already strings).

Regards,

Florian

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question