5 ms·
> Active Record Pattern is somehow controversial. What is controversial about AR?
by pc86 11y ago
> Active Record Pattern is somehow controversial.
What is controversial about AR?
- jsjohnst 11y agoMainly how easy it is to have zero clue that you're doing something horrible (SQL performance wise). Not positive that's what parent meant, but that's my guess.
- trm42 11y agoAR works nicely for simple basic queries but everything more advanced should be done with custom queries. That helps a lot :)
- jsjohnst 11y agoThe issue is that the line between simple and advanced is blurry, especially for an inexperienced developer. Maybe someday we (Royal we of all software engineers who build tools other engineers use) will learn there's a limit to abstraction layers applicability and put hard breaks into the code when that happens. I guess one shouldn't complain, the more tools allow developers to shoot themselves in the foot and not feel the pain until the leg needs to be cut off, the more variety of positions that will be open for engineers who've been there done that.
- reefoctopus 11y agoSimple: CRUD operations Advanced: Everything else
- jsjohnst 11y agoSadly, it's not that cut and dry. Even what seems to be a simple CRUD retrieve operation to an inexperienced developer could be a very costly thing to do due to relationships between entities.
- porker 11y ago> What is controversial about AR? How it represents rows as objects. How it makes people think about them. How it conflates modelling the domain with database structure. https://www.google.co.uk/search?q=activerecord+vs+datamapper https://www.google.co.uk/search?q=activerecord+vs+datamapper
- scient 11y agoSoooo one row of a collection represented as an object instance of a collection of instances is bad? Why?
- porker 11y agoNo not at all :) Slavishly mapping a row in a database table to an application object is bad. Off the top of my head, an example could be a Product, where the tables are something like: product - main product details product_option - options (e.g. Size, Colour) product_option_values - values for that specific option instance In my application I don't care about the database structure - whether the tables are normalised or storing everything in one huge serialized blob (or CouchDB, or ElasticSearch or... you get the picture). Instead you want to get the options and save changes straight back when editing the product. Now this is where my example breaks down as the Product needs to 'know' about what options are available (either to provide a nice API or to know what to display in the UI) and my schema doesn't allow for that (save a Product.getAllOptions() method) but I'll leave that as an exercise for my reader :)
- dragonwriter 11y ago> How it represents rows as objects. A row is the DBMS's model of an entity in the domain. An object is an object-oriented programming language's model of an entity in the domain. Representing domain entities as objects in the PL that are backed by rows in a database relation (view or table), which is what the Active Record pattern does, is reasonable. > How it conflates modelling the domain with database structure. Modelling the domain should drive both application and database structure; the Active Record pattern doesn't promote anything bad I can see there. There are particular choices in database design that are encouraged by the path of least resistance in some Active Record implementations and related tooling that are, perhaps, not so great.