Nishant Arora
Nishant Arora

Reputation: 388

How to add a particular migration with multiple entries in rails

I want to create a new field in my rails database which has multiple fields associated with it and can take multiple sets of entries. For example in Linkedin,

a user adds a job with information like title, description and duration and can create multiple jobs associated to his profile.

How do I build a similar system in rails, is it possible using only migrations or do I have to create a new model for it and associate it with a particular user.

Which will be the correct way to go through this issue?

Upvotes: 1

Views: 73

Answers (1)

Kirill V.
Kirill V.

Reputation: 67

You can create a new Job model, setup the relationship between the User and the Job models using a foreign key(user_id) and then inside User.rb put has_many :jobs and inside Job.rb put belongs_to :user, that way you will be able to create as many jobs as you want for a user. Not sure if this answers your question but I think that would be a better approach.

Upvotes: 1

Related Questions