What is the significant difference between an ORM with an active record and data?

Like doctrine (active record) and Xyster (data mapper), what's the difference?

+7
activerecord orm datamapper
source share
4 answers

The difference is how individual objects in your domain are at the data access level. With ActiveRecord, its only object that makes it very simple. Especially if your classes map one to one with your database. The data converter is more flexible and makes it easy to test your domain, regardless of any data access infrastructure code. But complexity comes at a price.

+3
source share

The main difference is that in DataMapper the model is defined in the ruby ​​class itself:

class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text property :created_at, DateTime end 

In ActiveRecord, the class is basically an empty class, and the HR service scans the database. This means that you either need a predefined database or use something like migration to generate the schema, which is why the data model is separate from the ORM.

 DataMapper.auto_migrate! 

will generate a circuit for you.

ActiveRecord is different in this respect:

 class Post < ActiveRecord::Base end 

There is no need for transfers in DataMapper, as automation can generate a schema or view the differences between the model and the database and migrate for you. There is also support for manual migration, which you can use for non-trivial cases.

In addition, DataMapper is a much more “ruby” syntax approach, and features such as lazy loading when binding conditions are met (for example, ActiveRecord in Rails 3) start from the very beginning.

Datamapper also has a function that each entry in the database maps to a single ruby ​​object, which is not true for ActiveRecord. Therefore, if you know that the database records are the same, you know that two references to the ruby ​​object will point to the same object.

On the flip side, while Rails 3 may promise you exchangeable frameworks, the Datamapper railtie (dm-rails) is not ready for production, and many functions may not work.

See page for details.

+1
source share

As the block header says, the difference is in how you choose to separate domain objects from the data access level.

In a nutshell, Active Record maps an object to a record in the database.

Here one object = one record.

From what I know, Data "mapper" displays an object with data, but it does not have to be a record - it can be a file.

Here one object should not be one record

This is because the purpose of this template is to preserve the representation in memory and the permanent storage of data independently of each other and the data converter itself.

Without putting this restriction of 1 object = 1, the Data Mapper makes these two layers independent of each other.

Any suggestions / corrections to my answer are welcome if I made a mistake somewhere.

+1
source share

I must admit that I do not know the doctrine or Xyster, but I can at least give an idea of ​​the difference between the active records implemented in Ruby and ORM, such as SubSonic, Linq to SQL, nHibernate and Telerik. Hopefully he will at least give you something for further study.

Ruby Active Record is its own data access library - it is not a mapping from an existing SQL interface library (for example, .NET SqlDataTables) into the language construct - it is an interface library. This gave developers more opportunities to create the library in a more integrated way, but also required them to implement a wide range of SQL tools that you would not normally find in ORM (for example, DDL commands are part of the Ruby Active Record interface).

ORMs are mapped to the base database structure using a manual step in which the code generator will open the database and check it - create objects that match the tables (and stored procedures) that it finds. These objects are created using low-level SQL programming constructs offered as part of the language (for example, the .NET System.Data.Sql and SqlClient libraries). The goal is to give the resulting relational databases a smoother, freer interface during programming: to reduce the "impedance mismatch" between the relational model and object-oriented programming.

As an additional note, MS made a very “active record” in creating native language constructs in C # via Linq to SQL and Linq to Entities.

Hope this helps!

0
source share

All Articles