アーティストを作成し、それをユーザーに関連付ける resque ジョブがあります。ユーザー has_and_belongs_to_many :artists、およびアーティスト has_and_belongs_to_many :users。
def self.perform(itunes_id, user_id=nil)
artist = Artist.find_by_itunes_id(itunes_id) || lookup_and_create_artist(itunes_id)
if user_id && user = User.find(user_id)
user.artists << artist
user.save!
end
end
user.artists << artist
この例外を発生させます:
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: artists_users.created_at may not be NULL: INSERT INTO "artists_users" ("artist_id", "user_id")
私はまた、artists_genres の作成を見てきました (Artist と Genre にも相互 HABTM 関係があります)。
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: artists_genres.created_at may not be NULL: INSERT INTO "artists_genres" ("artist_id", "genre_id")