DataMapper vs ActiveRecord (2)
ActiveRecord:
class Photo < ActiveRecord::Base
named_scope :for_public,
:conditions => "permissions.guest != #{Permission.enum[:none]}",
:include => :permission
end
include 不可省,懶得細究。enum 需要自己做 mapping.
繼承也不可省,每次 open 時都要 specify 正確的 parent.
DataMapper:
class Photo
def self.for_public
all(permission.guest.not => :none)
end
end
你說誰贏... 這根本太明顯了吧。
permission 這樣定義:
class Permission
permission = Enum.new(:none, :read, :write)
[:owner, :friend, :member, :guest].map{ |kind|
property kind, permission
}
end
只是 DataMapper 0.9.8 是爛的,所以暫時先用 0.9.7.
等到 0.9.9 出來後,再觀察一陣子,看看 dkubb 重整得如何。
希望從 0.9.9 開始可以進入穩定版... 這樣就可以開始試著扔掉 AR 了。
(目前 production server 勿用!@@)
0 retries:
Post a Comment
Note: Only a member of this blog may post a comment.