Skip to content

Implementation of the repository pattern for ActiveRecord, splitting domain model and persistence classes

License

Notifications You must be signed in to change notification settings

boochtek/activerecord-repository

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActiveRecord Repository

This is an implementation of the repository pattern for ActiveRecord. Using this allows splitting the domain model and persistence classes.

WARNING: This is currently merely a proof of concept. This means that testing and refactoring have often been put on the back burner.

TODO

  • Loading
    • Loading relations
      • Avoiding N+1 queries
  • Saving
    • Saving relations
  • Keep a registry of the repository classes
    • Indexed by the classes they map to
    • Use this to find repository class for relations
      • Caveat: What if there are 2 repositories for a relation we're looking for?
        • Need a way to specify that somewhere
          • In the repository is the only place that makes sense
  • Probably need to restrict other calls to Repository
    • User::Repository.create
  • Entity#initialize and #update should basically be the same
    • Maybe the only difference is that initialize will set things to nil
    • They could use a lot of refactoring
  • Relations between entities
    • belongs_to
    • has_many
    • has_one
    • has_many through:
    • Cascading deletions
  • Entity#changed?
  • Identity mapping
  • Use module builder pattern in ActiveModel.entity
    • Add more options
  • Use module factory (and module builder) pattern in ActiveRecord.repository
    • Add options
      • Setting entity class
      • Setting table_name
      • Setting a different primary key than id
      • Maybe define indexes
  • More validations

About

Implementation of the repository pattern for ActiveRecord, splitting domain model and persistence classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages