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
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 have version: 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 the slug+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 having v1 set for their versions when each course on its own should be able to do that.
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:
A course with a title of "hello" can have a version of "v1", "v2", "v3" as 3 different course records
Expected slugs for all 3 courses: hello, hello-v2, hello-v3
A course with a title of "world" can have a version of "v1", "v2", "v3" as 3 different course records
Expected slugs for all 3 courses: world, world-v2, world-v3
When adding a new course with a title of "hello" and a version of "v2" when this combo already exists would throw a uniqueness validation error if you had the 2 validation rules in the "This also doesn't work" section of this issue and if that validation didn't exist you'd get a PG index error because you have a unique index on the slug and version together
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.
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: