Keys are explicit in 0.9.0

0 views
Skip to first unread message

Sam Smoot

unread,
May 5, 2008, 10:09:53 PM5/5/08
to 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

unread,
May 8, 2008, 5:07:13 AM5/8/08
to 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
Reply all
Reply to author
Forward
0 new messages