Whenever I see an ORM that supports creating and transforming objects in bulk, I can't help but think about the poor misdirected users who forced it to do that. It's an Object-Relational Mapper. It maps objects. The whole concept isn't designed for bulk operations, the point is that you add logic to each and every record and convert your operations to SQL so that you never have to keep a lot of them in memory.

  • 6
    I disagree.

    There should be an easy way to update multiple records at once, such as `Order.where(“close_at < ?”, end_of_period).update_all(closed: true)`. Bulk processing!
  • 0
    Bulk operations should be fast. And all options must be correct; i.e. covered by tests. The "easy"-part is subjective and depends on the language.

    For example NHibernate (C#) is pretty straight forward: https://nhibernate.info/doc/...

    You can then add integration tests and have an excellent compromise between performance (plain SQL under the hood), correctness and readability (operation written in the main programming language of the project).

    Now we have two ways to modify data: the entity (good) and some random bulk-update (bad). We can unite both with the specification pattern, but that only increases complexity.

    So, as long as you don't have SQL-like statements in your ORM operations, you should be fine.
  • 0
    @Root The object part of ORM provides state guarantees not expressed in the database structure. Data which is accessed through an object and data which is accessed directly from the database should be isolated. Rails' way of allowing the user to bulk edit and destroy objects while silently skipping validation without even the guardrail of different classes for checked and unchecked operations is about as useful and safe as C's generics with void*
  • 0
    @lbfalvy There are safe and unsafe versions of those: #delete calls validations and hooks, #destroy does not. There are also safe and unsafe ways to update records (though I’m less familiar with them; it’s #update_column, I believe?). Use the one you need at the time (and unsafe versions are typically only used for cleaning data.)
Add Comment