Skip to content

Commit

Permalink
correção para criar usuario com chave estrangeira
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricio-araujoo committed May 20, 2024
1 parent f17d123 commit 339e6e6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backend/app/models/cargo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Cargo < ApplicationRecord
has_many :user
has_many :users
end
2 changes: 1 addition & 1 deletion backend/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class User < ApplicationRecord
belongs_to :cargo
belongs_to :cargo
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateCargos < ActiveRecord::Migration[7.1]
def change
create_table :cargos do |t|
t.string :type
t.string :nome

t.timestamps
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class CreateUsers < ActiveRecord::Migration[7.1]
def change
create_table :users do |t|
t.string :matricula
t.string :nome
t.string :matricula
t.string :email
t.references :cargo, null: false, foreign_key: true

t.timestamps
end
Expand Down
12 changes: 6 additions & 6 deletions backend/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/test/fixtures/cargos.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
cargos: MyString
nome: MyString

two:
cargos: MyString
nome: MyString
6 changes: 4 additions & 2 deletions backend/test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
matricula: MyString
nome: MyString
matricula: MyString
email: MyString
cargo: one

two:
matricula: MyString
nome: MyString
matricula: MyString
email: MyString
cargo: two

0 comments on commit 339e6e6

Please sign in to comment.