This isn't something that's going to be easy in any ORM, but here's an
idea.

What about caching a list of the members of a Grouping in an
attribute? You'd need to include the type obviously, so it would look
something like this:

'bar:1,bar:5,foo:2,frob:14'

You'd need to update this field when adding an element, and then
validates_uniqueness_of and/or unique key it in the DB.

Also note that you'll want to sort it, otherwise you'll run into
problems.

Dealing with users concurrently adding things to Groupings is a whole
'nother bucket of hurt, which will be trickier to deal with.

--Matt Jones

On Oct 23, 3:13 pm, raji <[email protected]> wrote:
> Ok, that's not the best subject line, but I couldn't think of a
> concise way to describe what I'm trying to do.
>
> I've got two models.  Grouping simply contains an id and a few other
> attributes (e.g. rating).  A grouping can contain many elements which
> are stored the Element model.
>
> A set of elements is tied together by a grouping_id.  An element can
> be one of several types of objects.  I'm doing this with polymorphic
> associations.
>
> 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?
>
> Thanks,
> Raj
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to