dimanche 20 septembre 2015

Zero or many association in ActiveRecord

I am new to rails and writing an application which has two models "job" and "sub_job" In my application job can have either zero , one or many sub_jobs

The has_many association will create one to many relationship for jobs.

I have written the following in the respective models

job model

has_many :sub_jobs

sub_job model

belongs_to :job

Now it means a job can have multiple sub_jobs but my question is:

Will has_many association handle the case when there is no subjob for a particular job ?

Aucun commentaire:

Enregistrer un commentaire