3 ms·
I want to like this article because I agree with the overarching general statement that the ActiveRecord pattern is troublesome. But it's... not very good. He
by cfv 7y ago
I want to like this article because I agree with the overarching general statement that the ActiveRecord pattern is troublesome.
But it's... not very good. He constructed his own interface in order to complain about it, an interface which is so subptimal that it lets him complain about how bad it is as if the pattern was somehow to blame.
In most Active Record implementations I've seen, a Record is a live tuple ("Active" "Record") and you typically have some form of Repository ("Books" maybe in this example?) alongside of it which is responsible for carefully and optimally building the record objects.
The pattern itself says nothing about how to query things, it talks about a kind of DAO that has convenience methods to access and manipulate a tuple.
Also, what's with the REST rant? I don't think I understand how that's linked.
- topspin 7y ago> He constructed his own interface in order to complain about it Yes, it is contrived, but it faithfully represents many examples I've seen in the real world. > Also, what's with the REST rant? I don't think I understand how that's linked. Why not? It's clearly explained. The typical REST API (as opposed to the well designed REST API) is just Active Record over HTTP: /something/:id called in N+1 loops. And this emerges for the same reason as it does in the Active Record pattern; the 'central abstraction' offered by REST is mapping every resource to a URL, as opposed to mapping every row to an object.
- cryptonector 7y agoA REST API on top of an ORM is going to have the same problems the ORM has. But you can have a RESTful interface to a relational database. For example, PostgREST is awesome.