-
-
Notifications
You must be signed in to change notification settings - Fork 588
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
Optional validations #42
Comments
No, this isn't possible with FriendlyId right now. Why you are using FriendlyId on a unique numeric column with no slugs? I think you are probably going to have problems, because your app at some point is not going to know whether you are looking for the record by its id or its friendly_id: Model.find("100") # is this the friendly_id or the real id? I don't know. In this case, FriendlyId will look for a record with FriendlyId "100" and if it's not found, it will fail over and look for a record with id 100, which will almost certainly cause problems for your application. If you want to avoid this failover behavior, you would need to use slugs. |
It's not a numeric value. An order number could be "AW123456" or similar. What I mean to point out is that its generation depends on the ID value. |
Ah, ok, I misunderstood. Still, it's not going to be possible with the current FriendlyId. I will likely be changing FriendlyId to generate the slug on If I were you, I would install friendly_id as a plugin or vendored gem for now, and just make a small patch to remove the validations. |
For now, I've reverted back to the previous version and I'll wait for a resolution. Thanks. |
It seems this isn't resolved, but the ticket's closed. Have you decided not to change this behavior? |
In fact, I was not intending to change it. However, I am now working on another feature that would allow models that use slugs to leave the slugs nil. I intend to generalize this functionality to non-slugged models, which would skip the validations when the friendly_id text is nil. This should allow you to do what you are trying to do. I expect to release this feature later this week. |
I'm using the latest friendly_id (2.3.0) on Rails 2.3.5. I have an Order model that has a "number" column. The number is populated immediately after creation because the value depends upon knowing the ID of the order. I want to use friendly_id on this column directly (no slug column) but my order creation dies with the following errors:
Am I able to deactivate or conditionally skip these validations?
The text was updated successfully, but these errors were encountered: