开发者

I need to specify a field name different than the table for association

Given I have an Artifact model an开发者_JAVA百科d 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜