Data Transfer Objects VS Domain/ActiveRecord Entities in the View in RoR

Posted by leypascua on Stack Overflow See other posts from Stack Overflow or by leypascua
Published on 2010-02-23T23:15:18Z Indexed on 2010/03/19 23:41 UTC
Read the original article Hit count: 459

Filed under:
|
|

I'm coming from a .NET background, where it is a practice to not bind domain/entity models directly to the view in not-so-basic CRUD-ish applications where the view does not directly project entity fields as-is.

I'm wondering what's the practice in RoR, where the default persistence mechanism is ActiveRecord. I would assert that presentation-related info should not be leaked to the entities, not sure though if this is how real RoR heads would do it.

If DTOs/model per view is the approach, how will you do it in Rails?

Your thoughts?

EDIT:

Some examples:
- A view shows a list of invoices, with the number of unique items in one column.
- A list of credit card accounts, where possibly fraudulent transactions were executed. For that, the UI needs to show this row in red.

For both scenarios, The lists don't show all of the fields of the entities, just a few to show in the list (like invoice #, transaction date, name of the account, the amount of the transaction)

For the invoice example, The invoice entity doesn't have a field "No. of line items" mapped on it. The database has not been denormalized for perf reasons and it will be computed during query time using aggregate functions.

For the credit card accounts example, surely the card transaction entity doesn't have a "Show-in-red" or "IsFraudulent" invariant. Yes it may be a business rule, but for this example, that is a presentation concern, so I would like to keep it out of my domain model.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about programming