使用的DataMapper来代替ActiveRecord的 [英] Use DataMapper instead of ActiveRecord

查看:730
本文介绍了使用的DataMapper来代替ActiveRecord的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataMapper的想法是肯定比ActiveRecord的好。它有多种数据存储,包括关系型数据库和NoSQL存储一个API。 DataMapper的是更聪明那么ActiveRecord的。它具有战略预先加载。此功能一手抹了N + 1查询问题。此外,它允许延迟加载,如文本财产遭受重大领域。 DataMapper的允许您创建和搜索任何复杂的对象图简单地通过提供条件嵌套的哈希值。 ActiveRecods不适于用于在生产中的关联。包括方法是丑陋的,不可配置。在2010年10月约什 - 西蒙兹发出<一个href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3662-exclude-fields-from-eager-loaded-models"相对=nofollow>补丁这种方法让字段被排除渴望加载。但是,这条道路被忽略,今天rails3,我们有相同的丑陋包括方法。

DataMapper idea is definitely better than ActiveRecord. It has one API for a variety of data stores, including RDBMS and NoSQL stores. DataMapper is much smarter then ActiveRecord. It has "Strategic Eager Loading". This feature single-handedly wipes out the "N+1 Query Problem". Additionally it allows lazy-loading of heavy fields like Text property. DataMapper allows you to create and search for any complex object graph simply by providing a nested hash of conditions. ActiveRecods is unsuitable to be used for associations in production. include method is ugly and unconfigurable. In October 2010 Josh Symonds makes a patch for this method to allow fields to be excluded from eager loaded. But that path was ignored and today in rails3 we have same ugly include method.

即使在Rails3辉煌AREL,ActiveRecord的是远离钢轨最好的ORM。你可能会说哇,那新的宝石metawhere允许写得真好code像 Article.where(:title.matches =&GT;'你好%',:created_at.gt =&GT; 3。 days.ago)。别急... DataMapper的支持了这一点,一箱!的也许不是修改的ActiveRecord,以貌似DataMapper的更好的是扩展并支持更好的ORM? DataMapper的更多详情,可 http://datamapper.org/ 被发现。

Even in Rails3 with brilliant AREL, ActiveRecord is far from the best orm for rails. You may say "wow, that new gem metawhere allows to write nice code like Article.where(:title.matches => 'Hello%', :created_at.gt => 3.days.ago)". But wait... DataMapper supports this out of a box! Maybe instead of modifying ActiveRecord to looks like DataMapper better is to extend and support better orm? More details of DataMapper can be found at http://datamapper.org/.

我认为,路轨在以后的版本应该使我们能够选择哪些ORM使用,就像现在它允许数据库的选择。即使它会只有一个选项的ActiveRecord,人们将寻找可用的替代品。当我开始学习轨道,我认为只有对ActiveRecord的支持。而后来我甚至没有试图寻找别的东西。

I think, that rails in later releases should allow us to select which orm to use, like now it allows a database selection. Even it will has only one option "ActiveRecord", people will search for available alternatives. When I was starting to learn rails, I thought that there is support only for ActiveRecord. And later I did not even try to look for something else.

为什么我写这些东西?我认为,我们需要更多地关注这个漂亮的ORM。如果你是一些流行的或不那么受欢迎的宝石开发商,想加入支持的DataMapper的。 DataMapper的社会应该写的ActiveRecord的或其他的ORM一些迁移指南,并保持UpToDate的文件和你可能会帮助他们。至于我,DataMapper的社会需要更多的人,你可能是其中之一。 这个ORM的唯一的缺点是缺乏文档,你可能会有所帮助。

Why I am writing all this stuff? I think, that we need to pay more attention to this nice ORM. If you are developer of some popular or not so popular gem, think about adding support of DataMapper. DataMapper community should write some migration guides from ActiveRecord or another ORM and keep documentation uptodate and your may help them. As for me, DataMapper community needs more people and you may be one of them. The only disadvantage of this ORM is lack of documentation and you may help.

所以,你怎么想的?

推荐答案

Rails 3中,您可以使用DataMapper的,只是没有默认。它你想使用的DataMapper与导轨3.只要做到这一点

Rails 3 allows you to use Datamapper, just not by default. It you do want to use datamapper with rails 3. Just do this


    rails new project_name -m http://datamapper.org/templates/rails.rb

Rails允许你选择,你甚至可以用--skip-主动记录选项。 :)(可能不是简单,但它的存在。

Rails allows you to select, you can even use the --skip-active-record option. :) ( May not be straightforward but its there.

,是的,DataMapper的是真棒。 :)

And yeah, Datamapper is awesome. :)

这篇关于使用的DataMapper来代替ActiveRecord的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆