Commit 115f6c107ef8deee52f10b39e5e7d08c8dd329db

Authored by Gabriela Navarro
Committed by Parley
1 parent f19d2ba5

more_inst_for_users: Add relation to institution and users.

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
db/migrate/20140818195821_remove_institution_from_user.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class RemoveInstitutionFromUser < ActiveRecord::Migration
  2 + def up
  3 + remove_column :users, :institution_id
  4 + end
  5 +
  6 + def down
  7 + add_column :users, :institution_id
  8 + end
  9 +end
db/migrate/20140818200738_create_institution_user_relation_table.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +class CreateInstitutionUserRelationTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :institutions_users do |t|
  4 + t.belongs_to :user
  5 + t.belongs_to :institution
  6 + end
  7 + end
  8 +
  9 + def down
  10 + drop_table :institutions_users
  11 + end
  12 +end
lib/ext/user.rb
@@ -2,7 +2,7 @@ require_dependency &#39;user&#39; @@ -2,7 +2,7 @@ require_dependency &#39;user&#39;
2 2
3 class User 3 class User
4 4
5 - belongs_to :institution 5 + has_and_belongs_to_many :institutions
6 6
7 validate :email_different_secondary?, :email_has_already_been_used?, 7 validate :email_different_secondary?, :email_has_already_been_used?,
8 :secondary_email_format, :email_suffix_is_gov? 8 :secondary_email_format, :email_suffix_is_gov?
lib/institution.rb
@@ -5,7 +5,7 @@ class Institution &lt; ActiveRecord::Base @@ -5,7 +5,7 @@ class Institution &lt; ActiveRecord::Base
5 attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, 5 attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type,
6 :juridical_nature, :sub_juridical_nature, :normalization_level, 6 :juridical_nature, :sub_juridical_nature, :normalization_level,
7 :version, :cnpj, :type, :governmental_power, :governmental_sphere 7 :version, :cnpj, :type, :governmental_power, :governmental_sphere
8 - has_many :users 8 + has_and_belongs_to_many :users
9 9
10 validates :name, :presence=>true, :uniqueness=>true 10 validates :name, :presence=>true, :uniqueness=>true
11 11
lib/institutions_users.rb 0 → 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +class InstitutionUser < ActiveRecord::Base
  2 + belongs_to :user
  3 + belongs_to :institution
  4 +end