Necesito crear una entidad ProductsRequests en rails que tenga dos columnas user_request y user_response, las cuales sean claves foráneas de mi tabla users. Estoy utilizando rails 5.1 y ruby 2.7.1 Estoy aprendiendo, soy nuevo en ruby
Migración productsrequests
class ProductsRequests < ActiveRecord::Migration[5.1]
def change
create_table :products_requests do |t|
end
end
end
MIgracion users
class DeviseCreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
## Database authenticatable
# t.string :id, null:false, default: ""
t.string :first_name, null: false, default: ''
t.string :last_name, null: true, default: ''
t.string :dni, null: false, default: ''
t.string :telephone, null: true, default: ''
t.date :date_of_birth, null: true, default: ''
t.string :role, null: false, array: true, default: []
t.boolean :active, null: false, default: true
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
add_index :users, :dni, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
Modelo user:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
belongs_to :enterprise, optional: true
has_many :product_request, optional: true
def is_active
return { message: 'user cant log in' } unless active
end
end
modelo ProductRequest
class ProductRequest < ApplicationRecord
belongs_to :user, optional: false
belongs_to :stock, optional: false
end