No apologies for the punny title! Anyway, here''s the thing. I know what I want to do but not sure of the right way to model it. So far I have this in place. User has_many :names User.username User.email Name belongs_to :user Name.given Name.gender Name.user_id So basically a User has a list of names that they manage some male and some female. Now what I''d like to do is this in plain English. I want to allow registered users to be able to comment on each others name *lists*, importantly not the individual names the lists of the names. So I''ve worked out I need a Comment model and a User should have_many Comments, so a comment needs a Body and a user_id - thing is the comment belongs_to a User and it belongs_to other users.... not sure if this makes sense... can anyone deconfuse me ? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey Bingo Bob. - Read Mike Hartl''s -- Chapter 10 & 11 in the 3.2 version here http://ruby.railstutorial.org/chapters/user-microposts?version=3.2#top - Also checkout the Ruby on Rails -- Active Record association guide section here http://guides.rubyonrails.org/association_basics.html It isn''t EXACTLy what you want, but both should lead you down a better path with associations etc., Hope that helps. Good Luck Sincerely, Kisha On Tue, Mar 20, 2012 at 10:55 AM, bingo bob <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> No apologies for the punny title! > > Anyway, here''s the thing. I know what I want to do but not sure of the > right way to model it. > > So far I have this in place. > > User > has_many :names > User.username User.email > > Name > belongs_to :user > Name.given Name.gender Name.user_id > > So basically a User has a list of names that they manage some male and > some female. > > Now what I''d like to do is this in plain English. I want to allow > registered users to be able to comment on each others name *lists*, > importantly not the individual names the lists of the names. > > So I''ve worked out I need a Comment model and a User should have_many > Comments, so a comment needs a Body and a user_id - thing is the comment > belongs_to a User and it belongs_to other users.... not sure if this > makes sense... can anyone deconfuse me ? > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Sincere Regards, Kisha Richardson -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Kisha - the links are useful, I was aware of them both by despite having a crack at this in the console (I find that''s a great place to try stuff out and experiment I can''t get there). 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 (I guess as an array of hashes so I can access the attributes?). Rod (3, male) Freddy (2, male) 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). 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. What''s blocking me most is whether I should build small methods/scopes and chain them together OR one large "do it all in one go" method/scope. Not to mention how to write it. Most grateful for any insight. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.