Coder Social home page Coder Social logo

Comments (6)

stefankroes avatar stefankroes commented on June 14, 2024

This is not possible right now and would require a lot of changes. Can you provide a use case?

from ancestry.

krisleech avatar krisleech commented on June 14, 2024

I guess the one that springs to mind is if you aren't using Rails' id field as you primary key, maybe you are using a permalink or some other kind of string, e.g a hash.

from ancestry.

stefankroes avatar stefankroes commented on June 14, 2024

You should always use the ID column as you primary key in Rails. If you also want to save permalink slugs that's just fine! Just use something like this to build the path:

def permalink; path.map(&:slug).join('/'); end

You should not use the content of the ancestry column directly.

from ancestry.

krisleech avatar krisleech commented on June 14, 2024

I would agree that in most circumstances its wise to use the ID column as your primary key, but sometimes there are good reasons for not using it, for example if you have a natural unique key (e.g ISBN number, Invoice Number, MAC address) or your using a GUID to aid data migration/sync between distributed systems.

from ancestry.

stefankroes avatar stefankroes commented on June 14, 2024

Even in those cases; please still just use an id column as well. What if we run out of ISBN numbers and the scheme changes or we start reusing them? What if your application that uses ISBN numbers needs to be extended to track unpublished books?

Also database are more efficient at looking up records with integer id columns; ISBN numbers, invoice numbers and mac addresses all contain special characters (:-/) which requires you to save them as a string. Same goes for generating ids and integrity contraints like uniqueness and foreign keys.

There is really no reason to just have both: an internal id and an external id like a isbn, mac address etc.

from ancestry.

krisleech avatar krisleech commented on June 14, 2024

I think natural versus artificial keys is a moot point. The choice is dependent on your data and stance on such things, there is no right/wrong. Because the Rails way is to have a artificial key for everything I understand this is an edge case, 99% of people will be happy with using the id, in fact more than likely that's all they'll have.

But it is perfectly valid to not want to use an artificial key. Merging data is hellish with auto-inc id's since they are not unique like UUID's, again not something 99% of Rails developers need to worry about.

from ancestry.

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.