This may be something totally simple, but I can't for the life of me get this working. For some reason, :autosave isn't actually autosaving underlying models.
Here is my schema:
create_table :albums do |t|
t.string :title
t.text :review
t.timestamps
end
create_table :songs do |t|
t.integer :album_id
t.string :name
t.integer :length
end
create_table :cover_arts do |t|
t.integer :album_id
t.integer :artist
end
Here are my models:
class Album < ActiveRecord::Base
has_many :songs, :autosave => true
has_one :cover_art, :autosave => true
end
class CoverArt < ActiveRecord::Base
belongs_to :album
end
class Song < ActiveRecord::Base
belongs_to :album
end
When I do the following in IRB for an album with cover art that is already in the database:
a = Album.find(1)
a.title = "New title"
a.cover_art.artist = "New Artist"
a.save
It updates the album record but not the CoverArt record. What am I doing wrong?