You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have a pages table with an integer column page_number and a foreign key book_id. I'd like to store pages for many books, but ensure that there is only one of each page number per book.
When next_value is calculated, the previous_value is a string (a uuid) such as "063d663a-8c2f-4ff1-8eb8-e3e3bcd2a75f". The if and first elsif fail, but the second elsif succeeds. The result of calling #next on that string is "063d663a-8c2f-4ff1-8eb8-e3e3bcd2a75g", which is an invalid uuid (since that trailing g is not hex.)
What do you think the best way to fix this would be? My opinion is that this is trying to be too clever with this whole next bit, rather than calling the generator for that attribute again.
The text was updated successfully, but these errors were encountered:
Yup, and this issue has been raised before: #402 and #587.
Sorry this issue has been so long-standing, I'm about to finish up a release, but I will try to make this a priority for the next release. In the meantime you can find a fix in #587.
Let's say I have a
pages
table with an integer columnpage_number
and a foreign keybook_id
. I'd like to store pages for many books, but ensure that there is only one of each page number per book.In my tests:
If I am using Postgres and my ids are uuid columns, this will fail roughly once every 16 times.
Specifically, this line:
https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb#L385
When
next_value
is calculated, theprevious_value
is a string (a uuid) such as"063d663a-8c2f-4ff1-8eb8-e3e3bcd2a75f"
. Theif
and firstelsif
fail, but the secondelsif
succeeds. The result of calling#next
on that string is"063d663a-8c2f-4ff1-8eb8-e3e3bcd2a75g"
, which is an invalid uuid (since that trailingg
is not hex.)What do you think the best way to fix this would be? My opinion is that this is trying to be too clever with this whole
next
bit, rather than calling the generator for that attribute again.The text was updated successfully, but these errors were encountered: