on 10-26-2015 4:02 PM
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:
1 | id | BIGINTFIXED | (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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much, Florian!
This data model has been set by a third party, who wants me to migrate it to SAP HANA.
The idea is to get the name and description of the group, and display it on different languages, deppending on the parameter "lang".
So it's mandatory the use of projections if you want to get an association, i guess. Because i've been able to access data from a single table without the $project() method. I'm i right?
thank you very much for your help.
Regards,
Luis
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.