Sam Smoot
未讀,2008年5月5日 晚上10:09:532008/5/5登入以回覆作者
登入以轉寄訊息
你的權限不足,無法在這個群組刪除訊息
登入以檢舉訊息
該群組的電子郵件地址為匿名,或你需要檢視成員電子郵件地址的權限才能查看原始貼文
收件者:DataMapper
A few new people have joined the IRC room lately, so just wanted to
drop a reminder: Keys are explicit in 0.9.0, and every model must have
a key.
Bad:
class Zoo
include DataMapper::Resource
property :created_at, DateTime
end
Good:
class Zoo
include DataMapper::Resource
property :name, String, :key => true
property :created_at, DateTime
end
Or:
class Zoo
include DataMapper::Resource
property :id, Fixnum, :serial => true # A :serial property is an
auto-incrementing key.
property :created_at, DateTime
end
So given the examples above, hopefully you see the rationale. Explicit
keys helps encourage natural-key usage. Which generally speaking can
be a good thing (or it can make updates really difficult, YMMV). More
than that, it's consistent no matter your usage. Which might be a
little more typing, but looks "right" to me.
I'd suggest that we update/publish a TextMate bundle and push out id-
>Tab to "property :id, Fixnum, :serial => true" and then nobody can
complain. :-)