raji wrote:
[...]
> I need a way to ensure that a grouping is unique. That is, there
> should not be two grouping_ids containing the exact same elements.
>
> The closest analogy I can think of is a composite primary key.
> Except, this is across multiple rows (instead of columns) and uses
> polymorphic association types and ids.
>
> Can this be easily done with Rails and ActiveRecord?
Well, you could write a custom validator, something like (untested):
class Grouping < AR::B
validate :must_have_unique_elements
def must_have_unique_elements
taken = (elements.first.groupings.find :element_ids =>
element_ids).empty?
# There's gotta be a more efficient way to write that query.
errors.add_to_base("That combination of elements already exists!")
if taken
end
end
I don't think there's anything off the shelf to make this easier, but I
might be wrong...
>
> Thanks,
> Raj
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---