Unable to add associations to Active Records model/table, Rails3.2.14
I am working on a simple job portal which has few tables/resources that I
generated using scaffold in rails and using ActiveRecord as ORM. Tables :
User, Jobs
My User has 2 roles, recruiters and applicant ( I am using rolify, cancan
gems)
These are the steps I performed:
1] Generate tables using scaffold. 2] Run db:migrate, I can see the tables
now 3] I added some belongs_to , has_one, has_many associations in the
mode/.rb file. 4] Run db:migrate:reset , to recreate the db schema that
includes associations 5] I dont see any foreign_key columns in the User,
Jobs table.
What command do I need to run after I add associations to table so that I
can see the foreign key columns in my tables ?
Note:
1] If my associations are incorrect (semantically) thats okay, since I can
change them eventually. However I dont see any errors when I run rake
db:migrate
2] I haven't done any changes to the migrations. Not sure if I need to do
something there ?
Models:
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :name, :email, :password, :password_confirmation,
:remember_me, :user_id
validates_presence_of :email
end
class Job < ActiveRecord::Base
attr_accessible :company, :desc, :location, :application_id,
:applicant_id
belongs_to :recruiters, :class_name => "User"
has_many :applications
has_many :applicants,:class_name => "User", through: :applications
end
class Application < ActiveRecord::Base
attr_accessible :applicant_email, :applicant_name, :recruiter_id,
:applicant_id, :user_id
belongs_to :jobs
belongs_to :applicants, :class_name => "User"
end
No comments:
Post a Comment