Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.hash in ActiveRecord

I am encountering a function (?) that I do not fully understand in Rails and ActiveRecord.

I am building a basic website where the user (created with devise) can upload a document (the fields are: title and the attachment) Therefore, when the users goes to www.website.com/documents/new he is present with a simple_form that asks him to write a title and attache a PDF. Once confirmed, the document is saved in the database and linked to the user. Everything works fine.

My question is the following: when I run rails console and run Document.last.hash (or for any other stored document), I get back a numeric field back such as: 3130256425345013276

Can someone explain me what it is? Is it a hash function (like SHA-256 algorithm) to secure the encryption in the database? If yes, among all the hash functions, which is the one ActiveRecord is using?

like image 807
Magofoco Avatar asked Dec 13 '25 04:12

Magofoco


1 Answers

Is it a hash function to secure the encryption in the database?

It is a hash function, but has nothing to do with encryption. It's used when you use objects as keys in hashes.

like image 126
Sergio Tulentsev Avatar answered Dec 15 '25 16:12

Sergio Tulentsev