On 23 March 2012 09:24, bingo bob <[email protected]> wrote:
> OK
>
> Thanks - I've had another think about it but I'd still appreciate any
> insight if possible. I had wondered if my data model is wrong but I
> don't think so, it's rather simple.
>
> Users have names and Names belong to users. It has to be like this as
> Users can individually sort their names (so they have a position
> attribute), therefore while the name Fred might be in the database
> several times, it's a different record each time and needs to be as it's
> "owned" by different users who may have it as a different position in
> their respective lists - I think it's ok to have it as I have it, but it
> seems to make collecting my stats a little more difficult.
>
> Here's another way of looking at it, the output/result I need.
>
> Given the schema above I need the result of the query/scope/find_all_by
> to look something like this.
>
> If we've got records like
>
> Freddy
> Freddy
> Mary
> Rod
> Rod
> Rod
> Jane
>
> I need a method to return all this so I have access to it in my
> controller and then view.
>
> Rod (3, male)

A couple of questions
Are all the Rod records identical except for which user they belong to?

> Freddy (2, male)

What if one of the Freddys is female?  Maybe not likely with this name
but there are names that can be both.

> Jane (1, female)
> Mary (1, female)
>
> So that's unique and with this order..
>
> 1. By occurences (most common first)
> 2. By name in alpha order
>
> I need access to the name and gender attributes as well as the count
> (which clearly is not an attribute).
>
> What would be the best way for this to be returned even (an array? a
> hash?)
>
> The end game is so that I can easily query my data sets and work out the
> 10 most popular names across the users.
>
> At a later date I'd also love to be able to move on from this and find
> stuff that's "trending", for example what's changing position the most
> in a given time period or what's most popular this week, last week, last
> month, last year. All that stuff and variants thereof.
>
> Thanks for your help so far and most grateful for any further insight.
>

-- 
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