Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "active_record"
- config = {
- adapter: "sqlserver",
- host: "localhost",
- port: 1433,
- username: "sa",
- password: "yourStrong(!)Password",
- database: "groupby"
- }
- class CreateUsers < ActiveRecord::Migration
- def change
- create_table :users do |t|
- t.string :role
- end
- end
- end
- class User < ActiveRecord::Base
- end
- ActiveRecord::Base.establish_connection config
- unless ActiveRecord::Base.connection.data_source_exists? :users
- CreateUsers.new.change
- 3.times do
- User.create(role: "member")
- User.create(role: "admin")
- end
- end
- p User.group(:role).pluck(:role)
- # p User.group(:role).exists?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement