doctrine(アクティブレコード)とXyster(データマッパー)のように、違いは何ですか?
4 に答える
違いは、ドメインオブジェクトがデータアクセス層からどれだけ離れているかです。ActiveRecordを使用すると、そのすべてが1つのオブジェクトになり、非常にシンプルになります。特に、クラスがデータベースに1対1でマップする場合。データマッパーはより柔軟性があり、データアクセスインフラストラクチャコードに関係なくドメインを簡単にテストできます。しかし、複雑さには代償が伴います。
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
While in ActiveRecord the class is mostly an empty class and the framwork scans the database. This means you need either a pre-defined database or use something like migrations to generate the schema, this keeps the data model separated from the ORM.
DataMapper.auto_migrate!
would generate the schema for you.
ActiveRecord is different in this regard:
class Post < ActiveRecord::Base
end
In DataMapper there is no need for migrations, as automigrations can generate the schema or look the differences between the model and the database and migrate for you. There is also support for manual migration you can use for non-trivial cases.
Also DataMapper is much more "ruby" syntax friendy, and features like lazy loading when doing chainable conditions (like ActiveRecord in Rails 3) are there from the beginning.
Datamapper also has a feature that every record in the database maps to one ruby object, which is not true for ActiveRecord. So 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 too.
On the counter side, while Rails 3 may promise you exchangeable frameworks, the Datamapper railtie (dm-rails) is not production ready and many features may not work.
See this page for more information.
doctrineもXysterも知らないことは認めざるを得ませんが、Ruby に実装されている Active Records と、SubSonic、Linq to SQL、nHibernate、Telerik などの ORM との違いについて、少なくともある程度の洞察を与えることができます。うまくいけば、少なくともさらに探求する何かが得られるでしょう.
Ruby の Active Record はネイティブのデータ アクセス ライブラリです。既存の SQL インターフェース ライブラリ (.NET SqlDataTables など) から言語の構造へのマッピングではなく、インターフェースライブラリです。これにより、設計者はより統合された方法でライブラリを構築する自由度が増しましたが、ORM では通常見られない幅広い SQL ツールを実装する必要もありました (たとえば、DDL コマンドは Ruby の Active Record インターフェイスの一部です)。 )。
ORM は、コード ジェネレーターがデータベースを開いてスキャンし、検出したテーブル (およびストアド プロシージャ) に対応するオブジェクトを構築する手動の手順を使用して、基になるデータベース構造にマップされます。これらのオブジェクトは、言語の一部として提供される低レベルの SQL プログラミング構造 (.NET System.Data.Sql および SqlClient ライブラリなど) を使用して構築されます。ここでの目的は、プログラミング中にレコード指向のリレーショナル データベースによりスムーズで流暢なインターフェイスを提供することです。つまり、リレーショナル モデルとオブジェクト指向プログラミングの間の「インピーダンスの不一致」を減らすことです。
補足として、MS は、Linq to SQL および Linq to Entities を介して C# にネイティブ言語構造を構築する際に、非常に「Active Record に似た」ステップを踏み出しました。
お役に立てれば!