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

UUID typecasting #174

Open
ekampp opened this issue Oct 31, 2019 · 1 comment
Open

UUID typecasting #174

ekampp opened this issue Oct 31, 2019 · 1 comment

Comments

@ekampp
Copy link

ekampp commented Oct 31, 2019

Hi there.

I'm using Neo4J, which uses this gem for attribute declaration.

I'm also building a Rails app that uses UUIDs as primary keys in my Postgres database. I would like to be able to reference these primary keys, e.g. user_id, and have them be of the UUID type.

This could look something like:

class Node
  include ActiveAttr::TypecastedAttributes
  attribute :user_id, type: UUID
end

Currently, I'm using type: String, but that doesn't ensure that the given value is actually a UUID, and I have to write Active Model validators to ensure this, which is a bit of a pain.

Any pointers on where to start working on a PR is much appreciated. Thanks.

ekampp added a commit to ekampp/active_attr that referenced this issue Oct 31, 2019
This introduces a UUID typecasting option, which effectively functions as a string, but coerced to nil unless the string exactly matches the UUID pattern.

This fixes issue cgriego#174
@mathieujobin
Copy link

problem is, non-string uuid are just large numbers. so the validation is even more tricky

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

2 participants