I'm building an API in rails, and I have 2 models : Vehicle which has_one: :document
class CreateVehicles < ActiveRecord::Migration
def change
create_table :vehicles do |t|
t.string :uuid, limit: 36, null: false, index: true
t.string :license_plate_id
t.integer :mileage
t.string :mileage_unit, default: 'km'
t.belongs_to :user, index: true
t.timestamps null: false
end
end
end
Vehicle.rb
class Vehicle < ActiveRecord::Base
audited
include UuidConcern
belongs_to :user
serialize :response, JSON
has_one :vehicle_document, dependent: :destroy
end
VehicleDocument belongs_to: :Vehicle
class CreateVehicleDocuments < ActiveRecord::Migration
def change
create_table :vehicle_documents do |t|
t.string :uuid, limit: 36, null: false, index: true
t.integer :status, default: 0
t.attachment :file
t.belongs_to :vehicle, index: true
t.timestamps null: false
end
add_index :vehicle_documents, :status
end
end
vehicle_document.rb :
class VehicleDocument < ActiveRecord::Base
audited
include UuidConcern
self.primary_key = :uuid
belongs_to :vehicle
end
the problem is that I want to use a uuid for the vehicle id. I don't want to expose the real ID outside of my API. how must I do this ? Do I have to do this in the migration file ? model ? Should I not be doing this ? Thanks a lot