Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID #45

Open
pywebdesign opened this issue Jan 6, 2015 · 3 comments
Open

UUID #45

pywebdesign opened this issue Jan 6, 2015 · 3 comments

Comments

@pywebdesign
Copy link

Here is a migration file for whoever use UUID, I really don't know How to Create an alternate generator to submit, but this could help someone!

class ActsAsFollowerMigration < ActiveRecord::Migration
  def self.up
    create_table :follows, id: :uuid do |t|
      #t.references :followable, :polymorphic => true, :null => false
      #t.references :follower,   :polymorphic => true, :null => false
      t.uuid :follower_id
      t.string :follower_type

      t.uuid :followable_id
      t.string :followable_type

      t.boolean :blocked, :default => false, :null => false
      t.timestamps
    end

    add_index :follows, ["follower_id", "follower_type"],     :name => "fk_follows"
    add_index :follows, ["followable_id", "followable_type"], :name => "fk_followables"
  end

  def self.down
    drop_table :follows
  end
end
@hchood
Copy link

hchood commented May 25, 2015

FYI, you can also use t.references to set up a polymorphic association if you pass it the type: :uuid option:

    create_table :follows, id: :uuid, force: true do |t|
      t.references :followable, type: :uuid, polymorphic: true, null: false
      t.references :follower, type: :uuid, polymorphic: true, null: false
      # ...
    end

@ngoanpro0207
Copy link

Đây là tệp di chuyển dành cho bất kỳ ai sử dụng UUID, tôi thực sự không biết Cách tạo trình tạo thay thế để gửi, nhưng điều này có thể giúp ích cho ai đó!

class ActsAsFollowerMigration < ActiveRecord::Migration
  def self.up
    create_table :follows, id: :uuid do |t|
      #t.references :followable, :polymorphic => true, :null => false
      #t.references :follower,   :polymorphic => true, :null => false
      t.uuid :follower_id
      t.string :follower_type

      t.uuid :followable_id
      t.string :followable_type

      t.boolean :blocked, :default => false, :null => false
      t.timestamps
    end

    add_index :follows, ["follower_id", "follower_type"],     :name => "fk_follows"
    add_index :follows, ["followable_id", "followable_type"], :name => "fk_followables"
  end

  def self.down
    drop_table :follows
  end
end

#45 (comment)

@ngoanpro0207
Copy link

#45 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants