Open nickjj opened 2 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Just replying so it doesn't get auto-closed by a bot.
Here's a stripped down example of what I have set up:
My database migration has:
The issue
I want to explicitly require that a version is always provided when creating a course such as:
Course.create!(title: "Yay for learning", version: "v1")
This works fine and you end up with a slug of
yay-for-learning
because the version didn't have to be taken into account to be unique.But if you run this a second time you'll end up with a slug of
yay-for-learning-v1
which technically allows you to haveversion: v1
twice which isn't what I'm trying to do.If you run it a third time you get
yay-for-learning-0fa8243c-78a9-4fe3-b89b-080117d98b57
as a slug since theslug+version
alone isn't unique.What I tried
I can't add
uniqueness: true
to the version on its own at the Rails validation level because that would prevent (2) completely different course titles from ever havingv1
set for their versions when each course on its own should be able to do that.This also doesn't work:
Because technically the slug gets generated with a UUID so the slug is always different. This is where I think the only way this can be solved is if Friendly ID provides a mechanism to disable UUIDs from being generated and instead bubble up an ActiveRecord validation error (or DB error if no validation exists at the Rails level).
Is there something I'm missing here?
What I'm trying to do
In case it's not clear my intent is:
hello
,hello-v2
,hello-v3
world
,world-v2
,world-v3
That last bullet is what I'm having trouble getting to work with Friendly ID because instead of letting this validation error happen it behind the scenes generates a UUID to "fix" the uniqueness issue.