What have you found for these years?

2008-10-12

ActiveRecord 根本就是莫名其妙...

1. method 命名與架構根本就不統一,東西常常要找半天
2. 裡面不知道有多少 "magic", 正常的 ruby 寫法加在上面常常跑不了
3. 往往不小心就搞壞 ActiveRecord 原本的運作方式...

正在寫 pagify 的心得。
還有之前寫不少擴充時也是,ruby 原本就很複雜了,被 AR 這樣一搞,
很多 include extend eval 機制都被他搞得更加混亂了...

怪不得有人會說 ruby 會把自己毀了。在 rails 上可能是最明顯的。
你看有多少 plugin 根本就在亂搞啊... 每個人都在行自己的方便,
都完全不管這樣有多容易打壞別人的東西!

老實講,真的寫到很不想幫 AR 寫東西了 @@
DataMapper 兩三下就搞定的東西,每次都會在 AR 卡好久。
好不容易 AR 能動了,DM 又會失效...

後來 test case 也乾脆用 DM 建 database, 再讓 AR 去連...
反正 DM 要連多個 database, 隨便改名字亂設定都不會有問題。


# i am tired with active record!!
DataMapper.setup :active_record, 'sqlite3:active_record.sqlite3'
class UserForActiveRecord
include DataMapper::Resource
property :id, Serial
property :name, String
def self.default_repository_name
:active_record
end
# 這邊有點奇怪,storage_name = 'users' 會怪怪的
storage_names[:active_record] = 'users'
auto_migrate!
end


不過撰寫 AR adapter 還是有助於我做 abstraction,
再加上為了移植方便,還是繼續做吧!

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0