SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    find with order sum

    I have 2 models:

    class Core < ActiveRecord::Base
    has_many :votes
    end


    class Vote < ActiveRecord::Base
    belongs_to:core
    end


    the model Vote has the vote attribute with -1,0,1 values

    I want to get the list of Cores (name,vote) with top vote.

    es.

    cores.name votes
    p 32
    aaa 10
    two 9
    three 8
    hello 6
    aaaa 5
    rrrr 4
    qqqq 3
    ccc -4
    eww -10

    I want to do it with a only query. (like i did it with php)
    How can i do??
    Thanks.

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should give you a few ideas:

    http://api.rubyonrails.org/classes/A...ssMethods.html

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks but now in list i must view also the number of comments.

    then
    cores.name votes comments

    how i can do?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •