I am new to rails and stuck on one Querying issue. Here is the
situation.

Model: Category
class Category < ActiveRecord::Base
has_and_belongs_to_many :postings
has_and_belongs_to_many :volunteers
end

Model: Posting
class Posting < ActiveRecord::Base
has_and_belongs_to_many :categories
end

Model: Volunteer
class Volunteer < ActiveRecord::Base
has_and_belongs_to_many :categories
end

-------
Now Here is the problem I am trying to solve

I want to find out all the postings of the categories that the
volunteer is interested in. The volunteer might be interested in more
than one categories and posting might be assigned more than one
categories.

Here is the basic pseudocode

vol=Volunteer.find 1
vol_cats=vol.categories
foreach(vol_cat in vol_cats)
{
postings=postings + vol_cat.postings
}


Thank you

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Jun 12, 2012 at 1:31 pm

    On 11 June 2012 16:03, sigdelsaroj wrote:
    I am new to rails and stuck on one Querying issue. Here is the
    situation.

    Model: Category
    class Category < ActiveRecord::Base
    has_and_belongs_to_many :postings
    has_and_belongs_to_many :volunteers
    end

    Model: Posting
    class Posting < ActiveRecord::Base
    has_and_belongs_to_many :categories
    end

    Model: Volunteer
    class Volunteer < ActiveRecord::Base
    has_and_belongs_to_many :categories
    end

    -------
    Now Here is the problem I am trying to solve

    I want to find out all the postings of the categories that the
    volunteer is interested in. The volunteer might be interested in more
    than one categories and posting might be assigned more than one
    categories.

    Here is the basic pseudocode

    vol=Volunteer.find 1
    vol_cats=vol.categories
    foreach(vol_cat in vol_cats)
    {
    postings=postings + vol_cat.postings
    }
    Is that not the same problem you posted a few days ago, and then
    posted the solution?

    Colin

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 12, '12 at 1:07p
activeJun 12, '12 at 1:31p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Colin Law: 1 post Sigdelsaroj: 1 post

People

Translate

site design / logo © 2021 Grokbase