MCQs > IT & Programming > Ruby On Rails > Best way to create primary key as a string field instead of integer in rails.

Ruby On Rails MCQs

What is best way to create primary key as a string field instead of integer in rails.

Answer

Correct Answer: when creating a new table don't add primary key using this create_table users, :id => false do |t| t.string :id, :null => false ...... end execute("ALTER TABLE users ADD PRIMARY KEY (id)") if not using id as primary key then in users model add the following line class User < ActiveRecord::Base self.primary_key = "column_name" .... end

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Ruby On Rails Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Ruby On Rails Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it