Hi
Is it possible to specify multiple columns to :unique option?
For example:
## I want to validate uniqueness of :book_id AND :author_id,
## but DataMapper validates them separately.
class Writing
include DataMapper::Resource
property :id, Serial
property :book_id, Integer, :unique => :u1
property :author_id, Integer, :unique => :u1
end
## OK
irb> Writing.create(:book_id => 1, :author_id => 1)
~ (0.000051) SELECT "id" FROM "writings" WHERE ("book_id" = 1) ORDER
BY "id" LIMIT 1
~ (0.000057) SELECT "id" FROM "writings" WHERE ("author_id" = 1)
ORDER BY "id" LIMIT 1
~ (0.001629) INSERT INTO "writings" ("author_id", "book_id") VALUES (1, 1)
=> #<Writing id=1 book_id=1 author_id=1>
## Failed, because :book_id=1 alread exists!
irb> Writing.create(:book_id => 1, :author_id => 2)
~ (0.000051) SELECT "id" FROM "writings" WHERE ("book_id" = 1) ORDER
BY "id" LIMIT 1
~ (0.000055) SELECT "id" FROM "writings" WHERE ("author_id" = 2)
ORDER BY "id" LIMIT 1
=> #<Writing id=nil book_id=1 author_id=2>
irb> _.errors.to_hash
=> {:book_id=>["Book is already taken"]}
--
regards,
makoto kuwata
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---