Hacker News new | ask | show | jobs
by vampirechicken 4926 days ago
> Models are intended to serve only as an abstraction to the database. > They are meant to be 'models of data'.

TL;DR: MVC Model is Logical model - business object (invoice) with business logic (delete_line_item), Rails Model is Physical model - persistence layer for RDBMS (add, update, delete, find rows).

In all but the most trivial applications, the latter assertion contradicts the former, and the former, is just outright wrong.

In MVC, Models are meant to model the logical objects of the system. An invoice is an object one which one acts. It is probably composed of several other objects (header, line items, addresses, etc.) which may in turn be composed of other objects.

Only the most trivial application have a one-to-one mapping from RDBMS rows to objects, which is what the OP asserts.

One does not write one's Models with the persistence layer in mind, one writes them with the business logic in mind.

So to me, this is where Rails gets the name Model wrong. The untrained, just starting out with rails learn that business logic goes in the model, so there is goes. But add_address() has no business living int he rails Model file for the invoice header, because that model is meant to be dedicated to manipulating invoice_header records in our RDBMS.

1 comments

mew , we all lived the Java/JEE nightmare , and pragmatic programmers got us out of that mess, with no desire to go back to that stuff. I'll take ruby/active record flaws over the "bloated and unecessary entreprise pattern" code anytime.
It might not be wise to go back to bloated JEE. However, it would certainly be unwise to leave the knowledge behind. People working in Rails and Django applications need to learn those important lessons. It can save them from a lot of common pitfalls. I have seen people using a large number of servers for Rails applications while similar load is handled by less half their number of servers using Java.
How did J2EE become a night mare. It was pretty clear to me that you put your business logic in session beans, and they manipulated entity beans along the way.