class Purchase
validate :validate_same_movie
private
def validate_same_movie
movie_ids = tickets.map do |ticket|
ticket.showing.movie.id
end.uniq
errors[:base] << "Can't have more than one movie in a purchase." if movie_ids.length > 1
end
end
Something along these lines.
But I would also urge you to think about exactly why you're introducing this additional complexity into your system. In my experience, I typically buy movie tickets for the same movie at once and I don't recall when I've bought tickets for different movies in a single purchase. But just because I haven't done it doesn't mean nobody does. You're adding complexity and you're reducing functionality of your site. I'm not saying you don't have a valid reason, because I don't know what your app is.. but just a suggestion that you might think about if you really need this.