Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse back from EntityKey.toString() to get FK #63

Open
mahish opened this issue Jan 20, 2022 · 3 comments
Open

Parse back from EntityKey.toString() to get FK #63

mahish opened this issue Jan 20, 2022 · 3 comments

Comments

@mahish
Copy link

mahish commented Jan 20, 2022

Hi,
I didnt find native way how to parse back a value returned from EntityKey.toString() (doc). I can see the returned string value is concatenated as follows: [EntityType.name, foreignKeyValue].join('-'). Is there any native, correct way how to get the FK(s)? Of course, I can do entityKeyString.split("-")[1] but feels dirty. Am I missing something? Thanks.

@mahish mahish changed the title Parse back from EntityKey.toString() Parse back from EntityKey.toString() to get FK Jan 20, 2022
@marcelgood
Copy link

marcelgood commented Jan 21, 2022

No, there is not. EntityKey.toString() creates a human readable representation. If you want to serialize/deserialize the key use EntityKey.toJSON() and EntityKey.fromJSON().

@jtraband
Copy link
Contributor

jtraband commented Jan 21, 2022

You can also look at the 'keyProperties' of the EntityType and then extract them from the entity yourself directly. See http://breeze.github.io/doc-js/api-docs/classes/entitytype.html#keyproperties

@mahish
Copy link
Author

mahish commented Jan 25, 2022

Thank you. I use the human readable version of EntityKey to create unique ID for presentation layer of my app (since it is more specific and safe than simple FK value). Eg.:

id: entityKey.toString(),
get parentId() {
  ...
  return parentEntityKey.toString();
},
set parentId(parentEntityKey) {
  ...
  // change value of FK property
  this.entity[propertyName] = parentEntityKey.split("-")[1];
}

As I can see there is specific mechanism with globally defined ENTITY_KEY_DELIMITER to get the string. So it would be nice to have a built-in method to parse it back. .toJSON does not help me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants