Open 9mm opened 11 years ago
Also, How do I make it a v1 UUID instead of v4?
Regarding the first question - please, show your sources. The second - try to redefine https://github.com/jashmenn/activeuuid/blob/master/lib/activeuuid/uuid.rb#L119 at your model.
Migration:
class CreateSurveys < ActiveRecord::Migration
def change
create_table :surveys, :id => false do |t|
t.references :employee, :null => false
t.uuid :id, :primary_key => true
t.datetime :expired_at
t.timestamps
end
add_index :surveys, :id
end
end
survey.rb
class Survey < ActiveRecord::Base
include ActiveUUID::UUID
belongs_to :employee
validates :employee, :presence => true
end
Looks proper, except add_index :surveys, :id
, primary keys in sql are indexed by default.
Still didn't get you. What is "MUL" then? Where did you see this?
Ah, got it. It is MUL because of add_index :surveys, :id
. Just remove this line and it will become PRI
That fixed it! Thanks! I saw the add_index
line right on the documentation, as well as a few guides online. I don't know why everyone has that in their examples if it's not supposed to be on a primary key... hmm.
I'm sure you are busy but would you mind answering a few straggling questions of mine, just for the sake of learning?
def token
id.hexdigest
end
def self.id_from_token(token)
UUIDTools::UUID.parse_hexdigest(token)
end
Thanks!
If you ask me - there is no indication to use activeuuid at all. In your place, I would make a usual autoincrement id and additional token field with uniq index to store hex values. And use simply before_save to generate this token.
I do not know about the difference between v1 and v4, but you can use whatever you need with http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html
I'm looking at my MySQL table after I set
:primary_key => true
, and it's saying instead of PRI it's "MUL". Is this okay?