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

Use a non autogenerated column as primary key #328

Closed
brafales opened this issue Jul 11, 2016 · 4 comments
Closed

Use a non autogenerated column as primary key #328

brafales opened this issue Jul 11, 2016 · 4 comments
Labels

Comments

@brafales
Copy link

Hi. We are trying to use hanami-model in a non standard way, and we are running into some issues. I'd like to see if we're using it the wrong way, we are missing something, or simply hanami-model was never intended to be used like this.

We are basically writing an app that will listen to some network events, and persist them into a database for further processing. The unorthodox behaviour here is that the actual primary keys of the records we want in the database are given to us by these events, and therefore we don't need (nor want) the database to use an autogenerated id field to keep track of those.

So in our implementation, we'd like to receive an event, create an entity for that event that has a custom uuid field that is part of the message, and persist that in the database using that uuid as the entity identity.

In order to achieve that we've tried several things, but none of them seem to have worked for us. Find below a link to a gist with the final configuration we've ended up with:

https://gist.github.com/brafales/2619eea7418d8dbb89b7dd245a401332

We'd appreciate some feedback on this approach. If it's something that is definitely not supported by the gem, or if we are simply not configuring it properly. Also, if this is a usage scenario you would consider supporting in the future.

If that doesn't work, we'll have to end up having an id field in the DB and use that as a primary key, and then add some extra logic in our repositories to track duplicates. However, in doing so, I think we'd lose a lot of the work hanami-model repositories give us out of the box.

Many thanks.

@beauby
Copy link
Contributor

beauby commented Oct 10, 2016

This commit that is part of this PR might be of interest.

@beauby
Copy link
Contributor

beauby commented Nov 11, 2016

This should be fixed on master now.

@jodosha
Copy link
Member

jodosha commented Nov 14, 2016

@brafales Hi, can you please check if the current version in master works for you?

@brafales
Copy link
Author

brafales commented Nov 14, 2016

It looks like a lot has changed since then, we moved to a different schema to allow both our own uuid and the autogenerated one, so it may not be worth investigating this anymore.

Hopefully when the move to ROM has been officially released I'll be able to revisit this.

Thanks for taking the time into looking at this!

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

No branches or pull requests

3 participants