has_many :through

I’m new in rails and I’ve some doubts about what kind of relationship do I have to use. Here the case.

I have two models Offer and User, a user could apply to many offers and offers can have many user also the users create the offers.

I think I have to use a has_many :through ralationship. for example I create another model “Applicant”, applicant belongs_to user and belongs_to offer. But how is the relationship from the user and offer model? for example

User Model

 has_many :offer, :through => :applicant

Offer Model

 has_many :user, :through => :applicant

My doubt is because I already have this two relationship

User Model

has_many :offers, :dependent => :destroy

Offer Model

belongs_to :user

After solve this doubt, I guest I have to save the record in the applicant model from the applicanst_controller, right?

Thanks in advance

Read: Active Record Associations — Ruby on Rails Guides

Thanks Jordon, I already read this article, and this is why I have my doubt.

I'm new in rails and I've some doubts about what kind of relationship do I have to use. Here the case.

I have two models Offer and User, a user could apply to many offers and offers can have many user also the users create the offers.

I think I have to use a has_many :through ralationship. for example I create another model "Applicant", applicant belongs_to user and belongs_to offer. But how is the relationship from the user and offer model? for example

User Model

has_many :offer, :through => :applicant

Offer Model

has_many :user, :through => :applicant

My doubt is because I already have this two relationship

User Model

has_many :offers, :dependent => :destroy

Offer Model

belongs_to :user

After solve this doubt, I guest I have to save the record in the applicant model from the applicanst_controller, right?

since you have the applicant model as the join table between offer and user, you won't need the user_id column on offer.

User Model

has_many :applicants has_many :offers, through: applicants

Offer Model

has_many :applicants has_many :users, through: :applicants

It doesn't matter where you save from. But it would be more logical to create the user first before the offer. Or if the offer already exists, create the user first, then the applicant.

One more thing, it may be confusing to use the model applicant. I think you need to change to some other name like application or user_offer which may make the associations more readable.