| > Fowler's "Enterprise Application Architecture", and it seems most of the people _using_ AR never read it I wasn't aware Fowler is a required reading for anything(or I would say even beneficial) for _anything_, let alone AR. > I particularly dislike the way it tends to result in code that is littered with leaky database abstractions where schema details tends to find its way into peoples controllers and views Your whole rant doesn't have anything concrete I can respond to. How does schema details creep into controllers and views? > because it encourages people to call AR methods on model objects directly instead of even trying to encapsulate. Ummm. What? I don't understand. Are you proposing person.save is wrong and save should be abstracted? > Ruby is my favorite language, but Active Record is one of the things I hold greatly against Rails, not only for AR itself, but for the inspiration it provided to many other Ruby ORM's, that while they may improve on various aspects still to a large extent also end up encouraging leaking implementation details for your models all over the place. More rant. Still nothing concrete. AR maps the whole table, and if you are using AR, you should know that. If you need to map parts of the table, or compose parts from various tables as one object, use something else. Not every tool has to solve every problem. |
Then I suggestion you read Enterprise Application Architecture. It's a great book for the way it formalises a number of very common patterns in a very concise way.
It is also directly or indirectly the inspiration for a large number of recent ORM's and worth reading for that reason alone. Active Record the ORM is a direct implementation of Active Record the pattern as described in EAR for example.
Unfortunately most picked off the easiest ORM pattern presented and stopped there, without alerting their users to all the caveats of the pattern.
> Your whole rant doesn't have anything concrete I can respond to. How does schema details creep into controllers and views?
Because the ORM spews methods all over the models that expose schema details whether or not they are relevant to the domain model.
> Ummm. What? I don't understand. Are you proposing person.save is wrong and save should be abstracted?
No, I am suggesting that, e.g. Person.where("some random SQL") is horrible. Yet it is hard enough to work with AR without resorting to crap like this, that you see stuff like that all over most code that uses AR. At least all the code I've looked at.
> More rant. Still nothing concrete. AR maps the whole table, and if you are using AR, you should know that. If you need to map parts of the table, or compose parts from various tables as one object, use something else. Not every tool has to solve every problem.
The problem is not what AR does, it is how it does it, and the way it's been packaged with Rails and given legitimacy that way despite being an exceedingly poor solution for anything but tiny projects because of a) the choice of the Active Record pattern, b) the poor level of abstraction.
A large chunk of developers are terribly excited about AR because it's better than what they're used to, and settle for it because it's part of Rails instead of looking for alternatives.