luis@328: class Authorship < ActiveRecord::Base luis@328: belongs_to :author luis@328: belongs_to :publication luis@393: luis@483: accepts_nested_attributes_for :author luis@483: accepts_nested_attributes_for :publication luis@483: luis@530: luis@518: # setter and getter for virtual attribute :user_id luis@519: def user_id luis@518: end luis@481: luis@530: def user_id=(uid) luis@530: unless uid.blank? luis@530: user = User.find(uid) luis@530: if user.author.nil? luis@530: # TODO: should reflect the name_on_paper parameter luis@530: author = Author.new :name => user.name luis@530: author.save! luis@530: user.author = author luis@530: user.save! luis@530: end luis@530: luis@530: self.author_id = user.author.id luis@519: end luis@518: end luis@328: end