Sam Smoot
unread,May 5, 2008, 10:09:53 PM5/5/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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. :-)