[LRUG] Field definitions in AR models

Tom Stuart tom at codon.com
Fri Feb 20 00:34:14 PST 2015


On 18 Feb 2015, at 11:33, Thomas Buckley-Houston <tom at tombh.co.uk> wrote:
> My problem with poking around the console is that it's counter to the
> MVC philosophy of using the Model to describe your domain.

I’m surprised nobody’s come out with the obvious-but-unhelpful smartarse answer yet, so I’ll just say it to clear the air:

The underlying problem is that Active Record is fit for use as a persistence layer, but not as your domain model. Ideally you would use it for the single concern of trafficking data between the database and a genuine layer of domain objects, which of course can be as rich, descriptive and documented as you like, being the single source of truth for model concerns. In this arrangement the only role of Active Record instances is to map directly onto the database tables and fields, so it makes sense for them to not re-represent this information in code; they’re simply the database reflected in a Ruby mirror. Your actual model objects can be much more than this.

Of course experience has shown that this is very difficult to achieve in practice because of the way that Rails and AR work, but hey, why let reality spoil our fun?

Cheers,
-Tom


More information about the Chat mailing list