okay, so, we have associations rocking

This commit is contained in:
Ken Johnson
2013-05-24 19:15:36 -04:00
parent 0d841124f5
commit 471c5851c7
7 changed files with 51 additions and 5 deletions
+4
View File
@@ -0,0 +1,4 @@
class Retirement < ActiveRecord::Base
attr_accessible :employee_contrib, :employer_contrib, :total, :user_id
belongs_to :user
end
+3 -2
View File
@@ -10,7 +10,8 @@ class User < ActiveRecord::Base
validates_format_of :email, :with => /.+@.+\..+/i
attr_accessor :skip_user_id_assign
before_save :assign_user_id, :on => :create
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id
def self.authenticate(email, password)
@@ -28,7 +29,7 @@ class User < ActiveRecord::Base
end
return auth
end
def assign_user_id
unless @skip_user_id_assign.present?
user = User.order("user_id").last
+1 -1
View File
@@ -6,7 +6,7 @@ class CreateUsers < ActiveRecord::Migration
t.boolean :admin
t.string :first_name
t.string :last_name
t.string :user_id
t.integer :user_id
t.timestamps
end
@@ -0,0 +1,12 @@
class CreateRetirements < ActiveRecord::Migration
def change
create_table :retirements do |t|
t.string :total
t.string :employee_contrib
t.string :employer_contrib
t.integer :user_id
t.timestamps
end
end
end
+11 -2
View File
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130424220355) do
ActiveRecord::Schema.define(:version => 20130524222129) do
create_table "retirements", :force => true do |t|
t.string "total"
t.string "employee_contrib"
t.string "employer_contrib"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "email"
@@ -19,7 +28,7 @@ ActiveRecord::Schema.define(:version => 20130424220355) do
t.boolean "admin"
t.string "first_name"
t.string "last_name"
t.string "user_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
+13
View File
@@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
total: MyString
employee_contrib: MyString
employer_contrib: MyString
user_id: MyString
two:
total: MyString
employee_contrib: MyString
employer_contrib: MyString
user_id: MyString
+7
View File
@@ -0,0 +1,7 @@
require 'test_helper'
class RetirementTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end