Composite Primary Keys and validates_uniqueness_of

2 views
Skip to first unread message

Learn by Doing

unread,
Jul 3, 2009, 9:50:03 PM7/3/09
to rubyonra...@googlegroups.com
This question regards the Composite Primary Keys gem
(http://compositekeys.rubyforge.org/) :

Once I use set_primary_keys, should I also use

validates_uniqueness_of to ensure that the composite primary key is
unique and

attr_readonly to ensure that the attributes in the primary key would
not be overwritten?

Thanks.
--
Posted via http://www.ruby-forum.com/.

Marnen Laibow-Koser

unread,
Jul 5, 2009, 2:20:15 PM7/5/09
to rubyonra...@googlegroups.com
Learn by Doing wrote:
> This question regards the Composite Primary Keys gem
> (http://compositekeys.rubyforge.org/) :
>
> Once I use set_primary_keys, should I also use
>
> validates_uniqueness_of to ensure that the composite primary key is
> unique

You could, but remember that the DB will catch that in any case.

> and
>
> attr_readonly to ensure that the attributes in the primary key would
> not be overwritten?

Depends. If you're using a composite key, presumably it's built up from
domain data, so in many cases, you wouldn't want to make it read-only.

What is your data like that you think you need this?

>
> Thanks.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Reply all
Reply to author
Forward
0 new messages