Below is my create function for my reviews controller. Basically the issue I have is that if a venue is left blank, and the artist isn't, an artist object is still created and a concert object is not. How do I prevent the artist from being created if the concert fails to create? If this isn't possible, how do I delete the artist immediately after the concert fails to create?
def create
date_string = "#{review_params['date(1i)']}-#{review_params['date(2i)']}-#{review_params['date(3i)']}"
artist_string = review_params[:artist].titleize
venue_string = review_params[:venue].titleize
@concert = Concert.find_or_create_by!(artist: Artist.find_or_create_by!(name: artist_string), venue: venue_string, date: date_string)
@review = @concert.reviews.create(review_params)
@review.user_id = session[:user_id]
end
artist has_many :concerts
concerts belongs_to artist
concert has_many reviews
I need to force an artist to have at least 1 concert.