has-friendship / has_friendship

Add friendship to ActiveRecord models
MIT License
198 stars 98 forks source link

Using UUID as primary key #54

Closed pcasa closed 6 years ago

pcasa commented 6 years ago

Could help others if readme had some pointers on how to use this gem with UUID's as primary key for associations?

Assumptions, User model has UUID as primary key and using enable_extension 'pgcrypto'.

Then alter the following migration files: ..._create_friendships.rb > NOTE t.references :friendable, polymorphic: true, type: :uuid and t.uuid :friend_id

def self.up
  create_table :friendships do |t|
    t.references :friendable, polymorphic: true, type: :uuid
    t.uuid  :friend_id
    t.string   :status

    t.timestamps
  end
end

..._add_blocker_id_to_friendships.rb > NOTE change from :string to :uuid

def self.up
  add_column :friendships, :blocker_id, :uuid, default: nil
end
chevinbrown commented 6 years ago

@pcasa uuid is not a solution that will work for everyone since there are some considerations one must make before using uuid as a pk.

If it is something you require, you can easily do that migration yourself without the help of this gem.

If we can generate some new releases, I'm hoping to make this a configurable option, but for now it is outside the scope of this gem.

sherpanat commented 4 years ago

I was just trying using this gem with uuid too. I didn't succeed in changing migration files so I tried what you gave us here @pcasa but it does not work. Did you succeed using thoses changes?