0

我有两个模型:摄影师和摄影师证书。摄影师有一个证书。

摄影师模型中已经有一个电子邮件字段。我想通过使用父表中的电子邮件字段作为设计的用户名来避免重复。

有什么想法吗?

4

1 回答 1

0

我不太明白你为什么需要第二个模型,但你的问题可以通过email在后面设置一个方法来轻松解决。

class PhotographerCredential < ActiveRecord::Base
  belongs_to :photographer

  def email
    photographer.email
  end

  # No email= method. This attribute should be set at Photographer

end
于 2013-10-17T17:44:22.390 回答