Tuesday 28 October 2014

Rails 4 uuid

http://blog.crowdint.com/2013/10/09/using-postgres-uuids-as-primary-keys-on-rails.html


Rails 4 out-of-the-box is that you don't need to include the ActiveUUID::UUID module in the models and when you create the migration, instead of using id: false you would use id: :uuid:
    class CreateStories < ActiveRecord::Migration
      def change
        create_table :stories, id: :uuid do |t|
          # To handle the relationship with the authors table
          t.uuid :author_id

          t.timestamps
        end
      end
    end
Use  postgresapp  http://postgresapp.com/


and enable extension

Select db and

CREATE EXTENSION "uuid-ossp";

In migration use

    create_table :partners, id: :uuid do |t|
      #  To handle the relationship with the authors table
      #t.uuid :author_id
    end

No comments:

Post a Comment