Answer the question
In order to leave comments, you need to log in
How to write validation rules for data not in ActiveRecord models?
There is a MySQL table in which records about goods (several millions) are stored.
The user can create / delete / update / view products in the admin panel. To do this, there is an ActiveRecord Product model, in which the validation rules are written.
There was a task: to upload (create + update) data about goods in csv, excel files (products in one file from a thousand to hundreds of thousands). Adapter classes were written for these formats, which read files in "pieces" (for example, 1000 records) in order to avoid jumps in memory consumption. To create and update records in the product table, the Importer class is written, which uses adapters to receive data in portions and sends them to the database (ON DUPLICATE KEY UPDATE is used).
And when writing the Importer class, the question arose: how to validate the data coming from the adapter? Duplicate the validation logic from the Product model or maybe there is a more beautiful solution? There are a lot of rules, and each time you make changes to the rules for the Product (in case of duplication), you will have to remember to change them in the Importer. Tell me please.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question