我有两个模特:摄影师和PhotographerCredential。摄影师只有一张证书。
摄影师模型中已经有一个电子邮件字段了。我想避免重复,使用电子邮件字段在父表作为用户名的设计。
有什么想法吗?
发布于 2013-10-17 17:44:22
我不太明白为什么您需要第二个模型,但是您的问题可以很容易地通过在后面设置email方法来解决。
class PhotographerCredential < ActiveRecord::Base
belongs_to :photographer
def email
photographer.email
end
# No email= method. This attribute should be set at Photographer
endhttps://stackoverflow.com/questions/19432864
复制相似问题