help with validates _uniqueness_of for a has_many table

6 views
Skip to first unread message

Scott Kulik

unread,
Jun 11, 2008, 3:00:27 PM6/11/08
to rubyonra...@googlegroups.com
i have a list of COMPOUNDS (combinations) that have any number of
COMPOUND_MATERIALS of which both are ITEMS. (this is for a video game
item database)

i want to validate that the compounds are unique by validating it's
combination of compound_materials does not already exist (a compound can
have multiple combinations of materials)

my tables:

ITEMS
id
name
...

COMPOUNDS (has many compound materials)
id
item_id

COMPOUND_MATERIALS
id
compound_id
item_id

so how would i use this in my model?

validates_uniqueness_of :item_id, scope =>
['compound_materials.item_id', ....

something like that but i'm confused because a compound can have any
number of compound_materials so I'm not sure how to write that out.

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

Reply all
Reply to author
Forward
0 new messages