title: Setting model association in Rails - saving 'from grandchild side'
body: <p>I'm a Ruby newbie so please forgive if some of these is complete ignorance. I want to set following associations:</p>
  
  <ul>
  <li>Transcription belongs to Composition</li>
  <li>Composition has many transcriptions, belongs to Artist</li>
  <li>Artist has many compositions (and transcriptions through compositions)</li>
  </ul>
  
  <p>I don't want to have any stand-alone forms for creating compositions and artists. Users just create transcriptions - the form for transcription has text fields fort artist and composition and database entries should be dynamically created (if they don't already exist).</p>
  
  <p>How should I set up models? Should I use some virtual attributes in Transcription?</p>
  
  <pre><code># transcription.rb
  def artist_name
    artist.name if self.artist
  end
  
  def artist_name=(name)
    self.artist = Artist.find_or_create_by_name(name) unless name.blank?
  end 
  </code></pre>
  
  <p>and later create Composition with <code>find_or_create_by_name</code> using artist I've found or created before?</p>
  
  <p>Any help appreciated! Thanks in advance</p>