Keys are explicit in 0.9.0

瀏覽次數:0 次
跳到第一則未讀訊息

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. :-)

myabc

未讀,
2008年5月8日 清晨5:07:132008/5/8
收件者:DataMapper


Sam Smoot wrote:

> 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. :-)

Dr. Nic has published a Merb TM bundle with DM support. Might be worth
pinging him with a patch:
http://github.com/drnic/merb-tmbundle/tree/master
回覆所有人
回覆作者
轉寄
0 則新訊息