Why does DataMapper use mixins vs inheritance?

So I'm just wondering:

DataMapper uses mixin for its models

class Post
  include DataMapper::Resource

While an active record uses inheritance

class Post < ActiveRecord::Base

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

+5
source share
5 answers

I think the idea is that ActiveRecord believes that the aspect supported by the base is a key feature of the model class, so it inherits this behavior. DataMapper looks like it believes that the database is only supported as one aspect of the class that can be added to the class.

. .

+3

, DM.

DM " ". , :

def datamapper_class
  klass = self.dup
  klass.send(:include, DataMapper::Resource)
  klass.storage_names[:default] = @table_name
  klass.property(:id, DataMapper::Types::Serial)
  klass.property(:created_at, DateTime, :nullable => false)
  klass.property(:updated_at, DateTime, :nullable => false)
  columns_with_types { |n, t| klass.property(n, t, :field => n.to_s) }
  klass
end

SAXMachine ( ) Datamapper , DataMappery. Singleton.

, , 100K XML ( DM ) ,

+5

DataMapper , . ActiveRecord .

per :

. , , . -, , . ; .

- , . , .

Data Mapper - , . , . Data Mapper , ; SQL , , . ( , .) Mapper (473), Data Mapper .

+4

Inheritance v.s. .

, .

, . , , . , .

0

ActiveRecord , ( , ) /. ActiveRecord !

MongoId MongoMapper, - .

Sadly, almost no one in the Rails community uses the “Ruby inheritance” as it should have used - to define class hierarchies, and not just to add behavior.

0
source

All Articles