Given I have an Artifact model and a User model: I would like to define two Artifact fields, opened_by and assigned_to, who values are User ids and inherit all of the proper association methods.
What is the proper belongs_to or has_one or has_many options I should set?
The goal is to be able to reference the user's name through the statement hld.assiged_to.name
where hld is an artifact.
Thanks for the help. I've gotten myself confused with terminology with all of the reading i've done on the problem.
The following is what I determined was correct.
class Artifact < ActiveRecord::Base
belongs_to :project
belongs_to :opened_by, :class_name => 'User'
belongs_to :assigned_to, :class_name => 'User'
The first argument in the belongs_to specifies the field to reference. The second indicates the model/class to use as the reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With