Search code examples
ruby-on-railsrubyinheritancedatamappermixins

Why does DataMapper use mixins vs inheritance?


So I'm just curious about this:

DataMapper uses a mixin for its Models

class Post
  include DataMapper::Resource

While active-record uses inheritance

class Post < ActiveRecord::Base

Does anyone know why DataMapper chose to do it that way (or why AR chose not to)?


Solution

  • I think the idea is that ActiveRecord considers the database backed aspect to be the key feature of a model class so it inherits that behavior. DataMapper looks like it considers being database backed to just be an aspect of a class that can be added to a class.

    That's my guess. Yehuda Katz could tell you definitively.