Code Monkey home page Code Monkey logo

Comments (6)

norman avatar norman commented on May 19, 2024

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.

from friendly_id.

laserlemon avatar laserlemon commented on May 19, 2024

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.

from friendly_id.

norman avatar norman commented on May 19, 2024

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 before_validate rather than before_save, which would solve problems like this. But I probably won't do this for a few more weeks.

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.

from friendly_id.

laserlemon avatar laserlemon commented on May 19, 2024

For now, I've reverted back to the previous version and I'll wait for a resolution. Thanks.

from friendly_id.

laserlemon avatar laserlemon commented on May 19, 2024

It seems this isn't resolved, but the ticket's closed. Have you decided not to change this behavior?

from friendly_id.

norman avatar norman commented on May 19, 2024

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.

from friendly_id.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.