Rails 7: implementing custom validations not being triggered during bulk insert operations
I'm having trouble with I'm relatively new to this, so bear with me. I'm working on a Rails 7 application where I have a model `User` that includes a custom validation to ensure that the email format is valid. The validation looks like this: ```ruby class User < ApplicationRecord validates :email, format: { with: URI::MailTo::EMAIL_REGEXP } end ``` However, I'm working with an scenario when trying to perform a bulk insert using `User.import` from the `activerecord-import` gem. I created an array of users to be inserted: ```ruby users = [ User.new(email: 'valid@example.com'), User.new(email: 'invalid_email'), User.new(email: 'another_valid@example.com') ] User.import(users) ``` The question is that the custom validation for the email format is not being triggered, and the invalid email gets inserted into the database. I expected to see an behavior or for the operation to unexpected result due to the validation. I've checked the documentation and it seems `activerecord-import` doesn't run validations by default to optimize performance, but I want to ensure that my validations run, even if it means sacrificing some performance. I tried passing the `on_duplicate_key_update: { conflict_target: [:email], columns: [:email] }` option during the import, but that didn't help with validation. Is there a way to enforce validations during a bulk insert with `activerecord-import`? Or should I consider an alternative approach like validating the records before calling import? I'd like to find a balance between performance and data integrity. Any suggestions on how to handle this situation would be greatly appreciated! This is part of a larger CLI tool I'm building. Am I missing something obvious? For reference, this is a production microservice. What's the correct way to implement this?