I'm a Ruby newbie so please forgive if some of these is complete ignorance. I want to set following associations:
- Transcription belongs to Composition
- Composition has many transcriptions, belongs to Artist
- Artist has many compositions (and transcriptions through compositions)
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).
How should I set up models? Should I use some virtual attributes in Transcription?
# 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
and later create Composition with find_or_create_by_name
using artist I've found or created before?
Any help appreciated! Thanks in advance