我有一个重新创建艺术家并将其与用户相关联的工作。用户 has_and_belongs_to_many :artists 和 Artist 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")