Browse files

More corrections based on test_data

  • Loading branch information...
1 parent 5f4c07f commit 58c303fa12e7aa7fb0ae00e189868448dbc198f2 @elight committed Mar 15, 2013
Showing with 18 additions and 13 deletions.
  1. +18 −13
@@ -3,11 +3,15 @@
[![Build Status](](
[![Code Climate](](
-Blog post describing EDR: ["Building Rich Domain Models in Rails. Separating Persistence"](
+Blog post describing EDR: ["Building Rich Domain Models in Rails. Separating Persistence"]( (though this post uses an older and more verbose version of the API).
# Description
-Originally named for "Entity, Data, Repository", building on the [Repository pattern](
+Originally named for "Entity, Data, Repository", based somewhat on the [Repository pattern]( The edr gem separates lookup, persistence, and domain model responsibilities into distinct classes.
+Domain Model classes are defined as "plain old Ruby objects" whose lifecycle is managed through a Repository class. The Repository creates Domain Model classes on DB reads and persisting them to the DB on saves through an ActiveRecord::Base. The Repository class can be viewed as a sort of simple [Data Mapper](, mapping a single database table onto a single Domain Model object. In this context, the ActiveRecord::Base subclass operates primarily as a [Row Data Gateway](
+Each Domain Model class has a single Repository that uses a single ActiveRecord::Base subclass.
# Example
@@ -33,7 +37,7 @@ ActiveRecord::Schema.define(:version => 1) do
-## STEP1: Define data objects
+## STEP1: Define data (Active Record) classes
``` ruby
class OrderData < ActiveRecord::Base
self.table_name = "orders"
@@ -54,7 +58,7 @@ class ItemData < ActiveRecord::Base
-## STEP2: Define Domain Model
+## STEP2: Define domain model classes
Fields and associations on the Domain Model are determined via ActiveRecord reflection. The Domain Model is coupled to its ActiveRecord class by naming convention.
@@ -76,23 +80,20 @@ end
## STEP3: map data objects to domain objects
-You probably want the below in a config/initializers/edr.rb
+You probably want the below in a <code>config/initializers/edr.rb</code>
``` ruby
-## STEP4: Define repository to access data
+## STEP4: Define repository classes
-Your Repositories arbitrate persistence on behalf of the Domain Model.
-While it is not ideal for the Domain Model to be aware of the Repository,
-we're stuck with this unless we add a [Unit of Work] reification to
-manage the relationship between the Domain Model and the Repository
+Your Repository class maps ActiveRecord CRUD results onto Domain Model instances.
``` ruby
module OrderRepository
- extend Edr::AR::Repository
+ extend Edr::Repository
set_model_class Order
@@ -112,7 +113,7 @@ module OrderRepository
module ItemRepository
- extend Edr::AR::Repository
+ extend Edr::Repository
set_model_class Item
def self.create_item order, attrs
@@ -122,9 +123,13 @@ module ItemRepository
+# Long term
+In an ideal world, the Domain Model classes would remain blissfully unaware of their Repositories. However, associations between Domain Model objects necessitate either awareness of the associated Domain Model class' Repository or arbitration via a [Unit of Work]( While a UoW could be defined/used by edr, this likely will remain beyond the scope of this gem.
+It is my hope that, in the near future, we will all instead switch over to using [Datamapper 2]( when it is ready. However, as of the time of the writing of this README, DM2 is still pre-alpha.
-## Installation
+# Installation
Add this line to your application's Gemfile:

0 comments on commit 58c303f

Please sign in to comment.