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

Choosing an alternate/custom EntityId field (or at the very least, exposing it by default). #194

Open
humblecoder opened this issue Jul 14, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@humblecoder
Copy link

So, I've seen the following two posts concerning EntityId customization:

https://github.com/redis/redis-om-node/issues/186
https://github.com/redis/redis-om-node/issues/40

However, I'm actually interested in selecting the field-name to which the value gets assigned, and revealing it (via toJSON(), or whatever else) for use with CRUD/REST functionality . As it stands, I currently destructure ({...myObj, id: myObj[EntityId]}) or use some version of Reflect.ownKeys(myObj) every time I need it. Would be nice to just have it "built-in" and available when the object is CRUDed.

I'm almost certain I'm missing something obvious in the documentation. 🤔

@guyroyse guyroyse self-assigned this Jul 17, 2023
@guyroyse guyroyse added the enhancement New feature or request label Jul 17, 2023
@guyroyse
Copy link
Contributor

I've been noodling on this a bit as the restructuring is a bit of a hassle. For now, that's the best way.

When I was putting this together, I first thought I would just store the entityId as a field named entityId on the returned object. But then I was concerened what would happen if that field was already there. So, I used a Symbol to avoid any conflicts.

I still want to stick with the Symbols as I think that utility is there. But I'm also thinking that maybe I could add a configuration option to the Schema to map the Entity symbol to a named property of your choice. And if that option isn't specified, then just default to current behavior.

I'm gonna mark this as a new feature and see about adding it in the near future.

@isque03
Copy link

isque03 commented Oct 16, 2023

This would be helpful:
"But I'm also thinking that maybe I could add a configuration option to the Schema to map the Entity symbol to a named property of your choice."

Thanks very much for your work on the project @guyroyse

@venticello
Copy link

I'm missing the ability to specify ID as a field. As is done in Redis om python.

class Thing(HashModel):
    thing_id: int = Field(index=True, primary_key=True, )
    class Meta:
        global_key_prefix = "MyProject"
        model_key_prefix = "thing"

This way I can easily use the keys that I already have in my database.
For example, my keys MyProject:thing:12345

@TomerAvni
Copy link

TomerAvni commented Dec 27, 2023

Hi there,
Thanks for this, very helpful!
Is there any progress here, or a way to expose it by default (similar to the previous version)?
Also, can someone here explain the logic behind the need to explicitly call a function whenever you need to use the id.
It is sooooooo error prone, it means you need to remember this every time you create a connection between entities, return forward this entity as a POJO, etc.
I am also not familiar with any other framework that does it (sql/nosql).
I honestly don't see the point, I'd love to understand it better...
But more important to get a solution, because for now, it makes this version not upgradable.

Thanks!

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

No branches or pull requests

5 participants